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

I can fully understand that there are requirements of using `:has()` inside `:host()`. And the discussion about the case may lead to the discussion of the `compound-selector` restriction on `:host()`. But I thought that this is a different issue of a confusion that can be discussed separately based on the current agreements. (I think that it is worth to clarifying this, regardless of how we agreed on the `compound-selector` restriction on `:host()` or `:host(:has())` cases)

In the perspective of spec reader, I thought that there might be a grey area on applying the `compound-selector` restriction to `:host(:has(div))` case, and it seems to be related to how to read `:has()` argument. So I thought that clarifying the grey area would be helpful for further discussion about `:has()` related cases including the `:host(:has())` cases.

This is how I understood the confusion so far:

1. The argument of `:has()` is a list of [`relative-selector`](https://www.w3.org/TR/selectors-4/#relative) which implies the anchor element at leftmost:
   > Relative selectors begin with a [combinator](https://www.w3.org/TR/selectors-4/#selector-combinator), with a selector representing the [anchor element](https://www.w3.org/TR/selectors-4/#relative-selector-anchor-elements) implied at the start of the selector. (If no combinator is present, the [descendant combinator](https://www.w3.org/TR/selectors-4/#descendant-combinator) is implied.)

2. Based on the relative selector definition, we should read the argument of `:has(div)` as `<has-anchor-element> <descendant-combinator> div`, not just `div`. And if this makes sense, I think that we should treat a `relative-selector` as a `complex-selector` because it always have a combinator.

3. If the above steps make sense, given the recent agreement of passing restrictions to the argument of logical combinations, the `:host(:has(div))` seems to violate the `compound-selector` restriction on `:host()` because the `:has()` argument `div` is a complex selector that has a `descendant-combinator`.

Among the above steps, I wanted to clarify the step 2 (how to read `:has()` argument) aside from the `:host(:has())` cases because I thought that it might be helpful for minimizing some confusions related to the differences between `compound-selector` and `complex-selector`.

I thought about adding a short note in the `complex-selector` description so that it helps reducing the confusion : *"`relative-selector` is a `complex-selector` as it always has a explicit combinator or an implicit descendant combinator. (e.g. the argument `div` in `:has(div)` is a `complex-selector` as it has implicit descendant combinator)"*

And I thought that this will not affect further discussions about `:host(:has())` case or `:host(<complex-selector>)` case because this just clarifies how to apply the `compound` restriction to a specific case.

-- 
GitHub Notification of comment by byung-woo
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10756#issuecomment-2311631559 using your GitHub account


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

Received on Tuesday, 27 August 2024 05:55:29 UTC