mirror of https://github.com/sveltejs/svelte
fix: improve event handling compatibility with delegation (#10168)
* fix: improve event handling compatibility with delegation * fix * lint * add testpull/10171/head
parent
a26012fc62
commit
0eca0ace94
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: improve event handling compatibility with delegation
|
@ -0,0 +1,20 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [b1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
b1?.click();
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
assert.deepEqual(log, ['clicked button']);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import { log } from './log.js';
|
||||
</script>
|
||||
<div on:click={(e) => { log.push('clicked div') }}>
|
||||
<button onclick={(e) => { log.push('clicked button'); e.stopPropagation() }}>
|
||||
Button
|
||||
</button>
|
||||
</div>
|
@ -0,0 +1,20 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [b1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
b1?.click();
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
assert.deepEqual(log, ['clicked button']);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import { log } from './log.js';
|
||||
const action = () => {}
|
||||
</script>
|
||||
<div use:action onclick={() => log.push('clicked container')} onkeydown={() => {}}>
|
||||
<div use:action onclick={(e) => { log.push('clicked div 1') }}>
|
||||
<div onclick={(e) => { log.push('clicked div 2') }}>
|
||||
<button onclick={(e) => { log.push('clicked button'); e.stopPropagation() }}>
|
||||
Button
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,25 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [b1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
b1?.click();
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
assert.deepEqual(log, [
|
||||
'clicked button',
|
||||
'clicked div 2',
|
||||
'clicked div 1',
|
||||
'clicked container'
|
||||
]);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import { log } from './log.js';
|
||||
const action = () => {}
|
||||
</script>
|
||||
<div use:action onclick={() => log.push('clicked container')} onkeydown={() => {}}>
|
||||
<div use:action onclick={(e) => { log.push('clicked div 1') }}>
|
||||
<div onclick={(e) => { log.push('clicked div 2') }}>
|
||||
<button onclick={(e) => { log.push('clicked button') }}>
|
||||
Button
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in new issue