Skip to content

:host(:has(...)) pointing to light DOM content #208

@Westbrook

Description

@Westbrook

Description

With a :host() selector referencing the root of an element with a shadow root, it holds that :host(:has(...) should reference light DOM children of that root. Some browsers acknowledge this truth (Safari), others don't (Chrome), others have yet to ship :has() support (Firefox).

Example: https://codepen.io/Westbrook/pen/KKoJNGm

In Safari with :has() support you get:
image

In Chrome with :has() support you get:
image

Rationale

There's no way to "know" what content has been slotted into a shadow root carrying element without leveraging JS API. The combination of :host() and :has() to form :host(:has()) means that advanced JS APIs are no longer required in order to style content (both in the shadow and light DOM).

Specification

https://drafts.csswg.org/selectors-4/#relational

Tests

I'm not sure (can't locate any) there are currently tests for this specific situation, but there should be!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions