[csswg-drafts] [selectors-4] Should `:has()` be a complex selector? (#10756)

byung-woo has just created a new issue for https://github.com/w3c/csswg-drafts:

== [selectors-4] Should `:has()` be a complex selector? ==
This is a follow-up question about the validity of `:host(<selector>)` argument ([csswg-drafts/issues/7953](https://github.com/w3c/csswg-drafts/issues/7953)) and the wpt pull request that adds tests for `:host(:has(section))` case ([web-platform-tests/wpt/pull/47441](https://github.com/web-platform-tests/wpt/pull/47441#issuecomment-2295058227)).

Given the fact that `:has()` represents a relationship between multiple elements, it seems reasonable to treat a selector containing`:has()` as a complex selector even if the selector is a form of compound selector. (e.g. `.a:has(.b)`)
- [selectors-4/#relational](https://www.w3.org/TR/selectors-4/#relational):
  > The relational pseudo-class, :has(), is a functional pseudo-class taking a [<forgiving-relative-selector-list>](https://www.w3.org/TR/selectors-4/#typedef-forgiving-relative-selector-list) as an argument. **It represents an element if any of the [relative selectors](https://www.w3.org/TR/selectors-4/#relative-selector) would match at least one element when [anchored against](https://www.w3.org/TR/selectors-4/#relative-selector-anchor-elements) this element.**

The spec describes that compound selector represents conditions on a single element and complex selector represents relationships between multiple elements:
- [selectors-4/#compound](https://www.w3.org/TR/selectors-4/#compound):
  > A compound selector is a sequence of [simple selectors](https://www.w3.org/TR/selectors-4/#simple) that are not separated by a [combinator](https://www.w3.org/TR/selectors-4/#selector-combinator), and **represents a set of simultaneous conditions on a single element**.
- [selectors-4/#complex](https://www.w3.org/TR/selectors-4/#complex):
  > A complex selector is a sequence of one or more [compound selectors](https://www.w3.org/TR/selectors-4/#compound) separated by [combinators](https://www.w3.org/TR/selectors-4/#selector-combinator). **It represents a set of simultaneous conditions on a set of elements in the particular relationships described by its combinators.**

If it makes sense, I think it might be helpful to add a comment to the complex (or compound) selector description that says that even if `:has()` describes a 'has-descendant' relationship (e.g., `:has(.a)`) which doesn't have an explicit combinator, it is a complex selector because of the implicit descendant relationship between the anchor element and the subject of the argument.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10756 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 19 August 2024 03:40:45 UTC