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

Test :host(:has(...)) and :host:has(...) selectors #47441

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

Westbrook
Copy link
Contributor

  • :host(:has(...)) works really well is Safari, sort of well in Firefox and not at all in Chrome. It's not really spec'd (IIUC) but normalizing on the output expected by developers and provided by Safari already seems like a good destination to work towards
  • :host:has(...) doesn't work anywhere and isn't spec'd anywhere (IIUC) but this is how I would tentatively expect it to work, similar to that way the :host(.class) references a class "outside" of the shadow root and :host:after references a pseudo element inside of the shadow root.

Both of these types of selectors would likely benefit from various combinator tests and

@tabatkins
Copy link
Contributor

Ooh, good question about :host:has(). I agree it should work, but the specs currently mandate that it doesn't; I've opened w3c/csswg-drafts#10693 to confirm and change this.

@tabatkins
Copy link
Contributor

Also, I appreciate that you're using the standard reftest for success, but I do prefer tests which fail with red when possible - mind putting the size and a red background on those elements with a lower-specificity selector, so the successful test will just override the color and make it green?

@Westbrook
Copy link
Contributor Author

I can dig into expanding the red/green results next week!

@Westbrook
Copy link
Contributor Author

@tabatkins this should have the good red/green fail => pass delivery now. Let me know if there's anything else I can do to prepare this for merging. 🙏🏼

@tabatkins tabatkins merged commit 8db7d12 into web-platform-tests:master Aug 13, 2024
19 checks passed
@Westbrook Westbrook deleted the host-has branch August 13, 2024 23:19
@byung-woo
Copy link
Contributor

byung-woo commented Aug 18, 2024

I've understood the current status of :host(:has()) as invalid case (w3c/csswg-drafts#7953 (comment)):

This means that :host(:has(...)) is invalid, since its arguments are inherently complex selectors (because they're relative, so there's a combinator), so imposing a compound-selector restriction on them makes all possible arguments invalid.

In case of :host(:has(section)), even if the argument of :has() is expressed as a compound-selector(section), it has the descendant combinator (' ') at leftmost which represents the ancestor-descendant relationship between the :has() anchor element and the subject element of the :has() argument selector.

If this understanding is correct (please correct me if I missed something), it seems that the :host(:has(section)) case need to be treated in the w3c/csswg-drafts#7953 similar to the other cases that violate the compound-selector restriction on :host() (e.g. :host(:has(> .a)), :host(:is(.a .b))).

How about making the test cases as tentative until there are some more clarification on the restriction?

Westbrook added a commit to Westbrook/wpt that referenced this pull request Aug 21, 2024
…s#47441)

* Test :host(:has(...)) and :host:has(...) selectors

* Add clear visual fail state
@Antoniodejesusmedina
Copy link

Antoniodejesusmedina commented Sep 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants