Problem inside shadow dom
See original GitHub issueHello!
Consider a <div>
to which a shadow dom is attached.
If I then add elements below this and use focus-trap for a child element (modal dialog im my case) the click event on the shadow dom will trigger for all those child elements and the event will be cancelled by this code:
var checkClick = function checkClick(e) {
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
return;
}
if (containersContain(e.target)) {
return;
}
if (valueOrHandler(config.allowOutsideClick, e)) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
}; //
If I change
if (containersContain(e.target)) {
to
if (containersContain(e.path[0])) {
it works.
path[0] will always be the actual clicked event, while the target in this case is the shadow dom parent.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
Using shadow DOM - Web Components | MDN
All you see in the DOM is the <video> element, but it contains a series of buttons and other controls inside its shadow...
Read more >What are the drawbacks of using Shadow DOM?
Shadow DOM features can be seen as drawback as much as benefits: Style isolation is a benefit if you want it but a...
Read more >5. Working with the Shadow DOM - Modern JavaScript [Book]
The shadow root is the root node for the shadow DOM branch. Shadow root child nodes are not returned by DOM queries even...
Read more >Shadow DOM and events - Il tutorial JavaScript moderno
Let's say, a click event happens inside a shadow DOM of <user-card> component. But scripts in the main document have no idea about...
Read more >Steps To Understanding the Shadow DOM - Medium
Therefore you can now see the true power of Shadow DOMs. The Global styles are no longer affecting any elements inside of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@andersthorsen FYI, I managed to get my PR working. I think it works well, for both mouse and tab key. I will publish this in the next few days, as early as Saturday.
@stefcameron
I’ve put up a pull request to add @andersthorsen! 🎉