question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem inside shadow dom

See original GitHub issue

Hello!

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:closed
  • Created 2 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
stefcameroncommented, Sep 23, 2021

@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.

0reactions
allcontributors[bot]commented, Sep 24, 2021

@stefcameron

I’ve put up a pull request to add @andersthorsen! 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found