Cannot modify native DOM event with CustomEvent in use:
directive action
#14502
Unanswered
kodaicoder
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The action only fires one event on mount and the event does not reach the handler. This is because Svelte 5 uses event delegation for regular DOM events like Compiler output for input.__change = [changeHandler]; If this is changed to e.g. $.event("modify", input, changeHandler); If you want to make sure the event is handled by event handlers using delegation, you have to make sure the event bubbles, there is an option for that on the event constructor: const customChangeEvent = new CustomEvent('change', {
detail: {
extraData,
timestamp: new Date()
},
bubbles: true, // <-
}); You also can manually use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://svelte.dev/playground/803e0d99397342d4a43fe26c7e5f5819?version=5.3.1
as per in REPL you will see that a input element have event handler to show a data that in event.detail and in actions.svelte.js there were has implement of CustomEvent to adding a detail data but enventaully there are not detail after event on change is fired.
this issue not persist if change CustomEvent's name to any other name that not matching with native DOM event (change, input, click, etc.)
Beta Was this translation helpful? Give feedback.
All reactions