Skip to content

[selectors][css-scoping] Should :host(:has()) match? #11859

@alisonmaher

Description

@alisonmaher

The group recently resolved to allow :host:has() per #10693 (comment). This allows an author to select the host element if it has a descendent in the shadow DOM matching a provided relative selector list.

:host(:has()) is similar to :host:has() except it would match against descendants in the light DOM. It was noted in that issue that :host(:has()) is already defined to work per the following comment #10693 (comment) and tests added in web-platform-tests/wpt#47441.

Safari already supports the tests for :host(:has()) added in web-platform-tests/wpt#47441, and Firefox supports some. Chromium does not yet support :host(:has()), but it does support :host:has().

There was some confusion on whether :host:(has()) is allowed, but per spec, it is not currently supported. The CSS Selectors spec notes that "Since :has() takes a <relative-selector-list>, its arguments are inherently complex selectors (because they start, perhaps implicitly, with a combinator). This means :has() cannot be used in contexts that don’t allow complex selectors; its arguments will be guaranteed to be invalid." And :host() is defined to take a <compound-selector>.

Given that some browsers already support :host:(has()), given we already support :host:has() variant, and given author use cases (as called out in #7953 (comment)) I am wondering if we should reconsider either:

  1. If :has() should be a <complex-selector> (which was discussed in [selectors][css-scoping] Should :host:has() match? #10693)
  2. Update what is allowed in :host() (which was previously discussed in [css-scoping-1] Clarify exactly what :host(<sel>) can use as argument #7953)

I suspect the latter of the two is more likely the route to take but would be open to thoughts from the wider community.

CC @tabatkins @Westbrook @justinfagnani

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Thursday Morning

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions