-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Option to let createEventDispatcher pass through shadow DOM #3327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Another issue i run into is that
function handleChange(val) {
this.dispatchEvent(
new CustomEvent("select", {
detail: val,
bubbles: true,
composed: true
})
);
}
function handleItemClick(event) {
// do something ...
handleChange(value);
}
function handleKeyDown(event) {
if (event.key === "Enter") {
// do something ...
handleChange(value);
}
} The temporary solution is that using |
Nice solution could also default composed and bubbles to true when the tag option is used. I believe that is the expected behavior when dispatching an event from a web component using createEventDispatcher but I'm new to Svelte so could be incorrect here. |
Closing as duplicate of #3119 |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
createEventDispatcher can't not pass through shadow DOM boundaries.
As describe here, Link to lit-element doc, by default, a bubbling custom event fired inside shadow DOM will stop bubbling when it reaches the shadow root.
To make a custom event pass through shadow DOM boundaries, you must set both the
composed
andbubbles
flags totrue
:Currently, you have to hack like this:
Describe the solution you'd like
Simple solution is like below:
Describe alternatives you've considered
Add another function like
createCustomDispatcher
to handle this case.Or
<svelte:host tag='custom-element' ref={that} attributes={['value', 'label']} />
which also allows you to reflect props to attributes for current custom component.
Or
<svelte:options ref={that} />
that allow you to access to
this
keyword, with it you can use something like:that.dispatchEvent
orthat.shadowRoot.querySelector()
How important is this feature to you?
I think this is important feature. Since you have no way but using hacky solution with
this
keyword.The text was updated successfully, but these errors were encountered: