Add support to use it inside a Shadow DOM. #251
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shadow DOM directly influences how event propagate through the DOM.
The shadow root is the root node for a shadow tree. It is possible to listen to any event originating from a shadow tree by adding the appropriate event listener directly on the shadow root.
Similar to how events work in the light DOM, events only bubble in the shadow DOM if the bubbles option is set to
true
:new Event('test', { bubbles: true })
.Events dispatched from within the shadow tree invoke the shadow root listeners if the event is marked as
bubbles
.By default, events don’t propagate outside shadow trees. This default behavior ensures that internal DOM events don’t inadvertently leak into the document.
For an event to traverse shadow DOM boundaries, it has to be configured as composed:
new Event('test', { bubbles: true, composed: true })
.This might be counterintuitive, but a composed event always propagates outside the shadow boundary regardless of whether it is bubbling or not.
The Event.prototype.composedPath method returns an array with all the nodes, in order, through which the event propagates.
That's why using
composedPath()[0]
guarantees to always refers to the correct "target".Source: https://pm.dartus.fr/posts/2021/shadow-dom-and-event-propagation/