-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: catch delegated events from elements moved outside the container (…
- Loading branch information
1 parent
8a85059
commit 15d6308
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: handle delegated events of elements moved outside the container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ages/svelte/tests/runtime-runes/samples/event-listener-moved-outside-container/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test } from '../../test'; | ||
|
||
// Tests that event delegation still works when the element with the event listener is moved outside the container | ||
export default test({ | ||
async test({ assert, target }) { | ||
const btn1 = target.parentElement?.querySelector('button'); | ||
const btn2 = target.querySelector('button'); | ||
|
||
btn1?.click(); | ||
await Promise.resolve(); | ||
assert.htmlEqual( | ||
target.parentElement?.innerHTML ?? '', | ||
'<main><div><button>clicks: 1</button></div></main><button>clicks: 1</button>' | ||
); | ||
|
||
btn2?.click(); | ||
await Promise.resolve(); | ||
assert.htmlEqual( | ||
target.parentElement?.innerHTML ?? '', | ||
'<main><div><button>clicks: 2</button></div></main><button>clicks: 2</button>' | ||
); | ||
} | ||
}); |
12 changes: 12 additions & 0 deletions
12
...ges/svelte/tests/runtime-runes/samples/event-listener-moved-outside-container/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
let count = $state(0); | ||
let el; | ||
$effect(() => { | ||
document.getElementsByTagName('body')[0].appendChild(el); | ||
}) | ||
</script> | ||
|
||
<div> | ||
<button bind:this={el} onclick={() => count++}>clicks: {count}</button> | ||
<button onclick={() => count++}>clicks: {count}</button> | ||
</div> |
15d6308
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
svelte-5-preview – ./sites/svelte-5-preview
svelte-octane.vercel.app
svelte-5-preview.vercel.app
svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview-svelte.vercel.app