Skip to content

Commit 09dff9b

Browse files
fix: allow custom element events on slot to bubble inside custom element (#13222)
Fixes #13162 We were going from parentNode to parentNode but if something is a slot of a custom element we should first go to the assignedSlot or else the inside of the custom element will be skipped. --------- Co-authored-by: Oscar Dominguez <[email protected]>
1 parent 6604e38 commit 09dff9b

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

.changeset/flat-flies-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: allow custom element events on slot to bubble inside custom element

packages/svelte/src/internal/client/dom/elements/events.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ export function handle_event_propagation(event) {
233233
while (current_target !== null) {
234234
/** @type {null | Element} */
235235
var parent_element =
236-
current_target.parentNode || /** @type {any} */ (current_target).host || null;
236+
current_target.assignedSlot ||
237+
current_target.parentNode ||
238+
/** @type {any} */ (current_target).host ||
239+
null;
237240

238241
try {
239242
// @ts-expect-error
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from '../../assert';
2+
const tick = () => Promise.resolve();
3+
4+
export default test({
5+
async test({ assert, target }) {
6+
target.innerHTML = '<custom-element><span></span></custom-element>';
7+
8+
const custom_element = target.querySelector('custom-element');
9+
10+
const logs = [];
11+
custom_element.callback = () => {
12+
logs.push('called');
13+
};
14+
15+
await tick();
16+
/** @type {any} */
17+
const span = target.querySelector('span');
18+
span.click();
19+
assert.deepEqual(logs, ['called']);
20+
}
21+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<svelte:options customElement="custom-element" />
2+
3+
<button onclick={(e)=>{
4+
$host().callback();
5+
}}>
6+
<slot></slot>
7+
</button>

0 commit comments

Comments
 (0)