Skip to content
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

[proposal] Node.containingShadowRoot #826

Open
emilio opened this issue Jan 31, 2020 · 4 comments
Open

[proposal] Node.containingShadowRoot #826

emilio opened this issue Jan 31, 2020 · 4 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@emilio
Copy link
Contributor

emilio commented Jan 31, 2020

I think this would be useful for authors that want to write Shadow-DOM aware code.

All browser engines have a way to get a hand to the subtree root and check if it's a shadow root in one way or another.

Gecko: https://searchfox.org/mozilla-central/rev/2e355fa82aaa87e8424a9927c8136be184eeb6c7/dom/base/nsINode.cpp#699

WebKit: https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/dom/Node.cpp?rev=+254087#L1127

Chromium: https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/dom/node.cc;l=1815;drc=95e78e2d51fce9616e316073be6b2b92189e21ee

How do folks feel about this? Maybe it should just be in Element and Text or something...

cc @whatwg/components

@caridy
Copy link

caridy commented Jan 31, 2020

@emilio can you provide more details and use-cases for this? Just curious how is this different from accessing the root node? what should be the behavior when the element is disconnected, etc?

@emilio
Copy link
Contributor Author

emilio commented Jan 31, 2020

It would not different to accessing the root node, but it can be O(1) rather that going through all the parents.

I just got a case where I wanted to check the activeElement of the containing tree, so (element.containingShadowRoot || document).activeElement.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM) labels Feb 1, 2020
@emilio
Copy link
Contributor Author

emilio commented Feb 1, 2020

I guess getRootNode() would also work, kinda. You wouldn't have the "is a shadow root" check built-in but that seems acceptable.

@annevk
Copy link
Member

annevk commented Feb 3, 2020

If we wanted to we could add some kind of filtering to that method via a dictionary member, but not sure if it’s worth the trouble. Depends a bit on how often it comes up I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM)
Development

No branches or pull requests

3 participants