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

[selectors] Validity of selectors nesting :has(), :is() and :has() #8441

Closed
faceless2 opened this issue Feb 10, 2023 · 2 comments
Closed

[selectors] Validity of selectors nesting :has(), :is() and :has() #8441

faceless2 opened this issue Feb 10, 2023 · 2 comments
Labels
selectors-4 Current Work

Comments

@faceless2
Copy link

We're redoing our :has() implementation due to #7676 and #7344 and I hit this case:

div, x:has(:is(:has(:foo))) { background: red }
div, x:has(:is(:has(div))) { background: red }

I'm not sure which of these statements is true

  1. Both selectors are valid; although :has(:foo) and nested :has() are invalid, the forgiving nature of :is() means it's ignored.
  2. The first selector is valid, because the inner :has() is invalid so it's ignored. The second is invalid; it's a nested :has()
  3. Both selectors are invalid; there's a nested :has()

Safari goes for option 1, Chrome is option 3, and I think it should probably be option 2 - the forgiving nature of :is() seems like it should take priority to me.

Testcase at https://jsbin.com/roxukig/edit?html,output

@faceless2 faceless2 added the selectors-4 Current Work label Feb 10, 2023
@tabatkins
Copy link
Member

As currently written, the spec requires the inner :has() to be the one that's invalid. The outer :has() just provides a parsing context that causes the invalidity; it doesn't care, itself, about why something is invalid inside of it. (And avoiding this sort of inconsistency is why the spec is written as it is, rather than invalidating the outer :has().)

So in both cases, the selectors are valid, but the :is() discards its arguments due to the nested :has() being invalid. So your option 1 is correct.

@faceless2
Copy link
Author

No action required so closing, but noting that as of today Chrome and Safari both go with Option 1, Firefox is option 3.

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

No branches or pull requests

2 participants