Skip to content

[css-scoping] :has-shadow pseudo-class #11007

Description

@LeaVerou

It is currently impossible to detect elements with a shadow root without direct traversal and checking element.shadowRoot for every single element, which is costly.

This is useful for a variety of DOM traversal use cases, so they can identify which elements they need to do extra work on. For example fetching elements of a particular type across the entire flattened tree, or even cloning a subtree that may contain declarative shadow roots (which disappear with regular cloning).

Beyond qSA use cases, :has-shadow would allow handling the state where a CE has been defined (so :defined matches) but not yet properly initialized.

It’s probably pretty easy to add a pseudo-class for this that matches if the element has an open shadow root. Not sure if matching a closed shadow root is desirable. Combined with #11001, this becomes even more powerful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Agenda+ FTF

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions