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

[css-selectors] new pseudo class that matches shadow hosts #2908

Open
TakayoshiKochi opened this issue Jul 12, 2018 · 4 comments
Open

[css-selectors] new pseudo class that matches shadow hosts #2908

TakayoshiKochi opened this issue Jul 12, 2018 · 4 comments
Labels
css-scoping-1 Current Work

Comments

@TakayoshiKochi
Copy link
Member

We would like to propose a new :has-shadow pseudo class that matches an element with open shadow root attached. The name is tentative and I am open to discussion for any alternatives.

The expected use cases are mostly for searching shadow host element, to run querySelector recursively, as we lost >>> combinator. For styling purpose, :host and :host(), or custom element default style satisfy most of the needs, I believe.

See also whatwg/dom#665 for more context.

@ewilligers
Copy link
Contributor

ewilligers commented Jul 12, 2018

Would this only be needed in the livestatic profile, like :has? i.e. would it be sufficient if the selector could only be used in querySelector[All], and not in style rules?

@tabatkins
Copy link
Member

(I editted your comment to refer to the static profile that you meant.)

We only have the static profile for things that are problematic for perf reasons to be live. I want to absolutely minimize what goes in there; it's very confusing for authors to be able to use something in qSA() but not in stylesheets. Even if we don't know of any use-cases for this in a normal stylesheet, keeping the language consistent is important for usability.

Anyway, I support this proposal, seems reasonable.

@castastrophe
Copy link

Possible use-case for this in CSS: being able to add a style only to the web components on the page, either as a means of debugging or passing down specific styles.

@Westbrook
Copy link

How would we expect something like this to work with an element that has a shadow root as applied by the user agent?

Image of the User Agent applied shadow root for an input element

Similarly, would we expect this pseudo class to work differently between open and closed shadow roots? Is a user agent shadow root technically closed, anyways?

I do like the idea that it supports better collection of elements with shadow roots. Having this capability also make me feel like there's some glimmer of a possibility that 3rd party tools (Hotjar style analytics, ARC toolkit style extensions, etc.) would be more eager to expand their coverage to sites that leverage shadow DOM by reducing the tree walking needed to activate their features in that context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-scoping-1 Current Work
Projects
None yet
Development

No branches or pull requests

5 participants