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

:has() pseudo-class #134

Closed
jensimmons opened this issue Sep 15, 2022 · 7 comments
Closed

:has() pseudo-class #134

jensimmons opened this issue Sep 15, 2022 · 7 comments
Labels
accepted An accepted proposal focus-area-proposal Focus Area Proposal

Comments

@jensimmons
Copy link
Contributor

jensimmons commented Sep 15, 2022

Description

The :has() pseudo-class fulfills the decades-long desire for a "parent selector", while adding even more power to CSS.

:has( ) allows other selectors as arguments, including :pseudo-classes. Exactly which :pseudo-classes are supported is likely not yet 100% interoperable. As of the writing of this article, for example, Safari supports: :nth-child, :nth-last-child, :first-child, :last-child, :only-child, :nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :modal, :target. And does not yet support dynamic media pseudo-classes like :playing, :paused, :muted, etc. It would be useful to align browsers on which :pseudo-classes are supported.

Pseudo-elements should not be allowed inside :has(). And there are other disallowed things, including :has() — you cannot create :has(:has()). Making sure browsers are interoperable on what they disallow is also useful for web developers.

There is no part of the definition of :has() that should not be included in Interop 2023.

Rationale

Listed as number two in 2021 State of CSS

Specification

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

Tests

Existing tests:

More tests may be needed, including for invalidation.

@jensimmons jensimmons added the focus-area-proposal Focus Area Proposal label Sep 15, 2022
@lilles
Copy link
Member

lilles commented Sep 15, 2022

There's a massive amount of invalidation tests for :has() in https://wpt.fyi/results/css/selectors/invalidation

@jensimmons
Copy link
Contributor Author

jensimmons commented Sep 15, 2022

It would be great to help update the MDN BDC data for :has(), so pseudo-class support is enumerated for each possibility, like :has(:target). That will help web developers know what works where, and avoid confusing bugs.

@foolip
Copy link
Member

foolip commented Sep 16, 2022

It would be great to help update the MDN BDC data for :has(), so pseudo-class support is enumerated for each possibility, like :has(:target). That will help web developers know what works where, and avoid confusing bugs.

@jensimmons can you file an issue at https://github.com/mdn/browser-compat-data/issues? That sounds valuable, but I think some guidance is needed to get it right. In particular, what the distinct possibilities are, is :target special or is it all pseudo-classes, and so on...

@gsnedders gsnedders added this to the Interop 2023 milestone Sep 16, 2022
@jensimmons
Copy link
Contributor Author

@foolip Good idea. Done: mdn/browser-compat-data#17818

:target is not special. It's just top of mind.

@Westbrook
Copy link

Support :host(:has(...))!!!

@foolip foolip moved this to Proposed in Interop 2023 Oct 7, 2022
@foolip foolip removed this from the Interop 2023 milestone Oct 7, 2022
@bkardell bkardell changed the title :has() pseudo-element :has() pseudo-class Oct 12, 2022
@foolip
Copy link
Member

foolip commented Nov 10, 2022

Adding to the rationale, :has() was one of the most common responses the State of CSS 2022 question about browser incompatibilities, mentioned in ~19% of responses, see #248.

@foolip foolip added the accepted An accepted proposal label Feb 1, 2023
@foolip
Copy link
Member

foolip commented Feb 1, 2023

Thank you for proposing :has() for inclusion in Interop 2023.

We are pleased to let you know that this proposal was accepted as the :has() focus area. You can follow the progress of this Focus Area on the Interop 2023 dashboard.

For an overview of our process, see the proposal selection summary. Thank you for contributing to Interop 2023!

Posted on behalf of the Interop team.

@foolip foolip closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted An accepted proposal focus-area-proposal Focus Area Proposal
Projects
No open projects
Status: Proposed
Development

No branches or pull requests

5 participants