Add simple parsing support for :has()
Categories
(Core :: CSS Parsing and Computation, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox103 | --- | fixed |
People
(Reporter: emilio, Assigned: tlouw, Mentored)
References
Details
(Keywords: dev-doc-complete)
Attachments
(1 file)
It should take a forgiving selector-list as described in the spec:
https://drafts.csswg.org/selectors-4/#has-pseudo
Parsing it behind a flag and maybe implement selector-matching on it should be relatively straight forward.
To implement simple matching, we probably need to add an fn first_element_child(&self) -> Option<Self>
to the selectors tree module. But that can be a follow-up if needed.
Assignee | ||
Comment 1•2 years ago
|
||
Adding the :has pseudo class and traversing children to find matches is simple enough.
There is an issue with parsing the selector passed into the selector list though. The spec says you can pass combinator selectors like this:
p:has(> a)
...which is not parsed correctly by the current implementation, because combinator selectors expect a preceding type selector, e.g.:
p > a
...so the > a
is not parsed as a selector correctly and is skipped.
I will push the changes for the initial implementation and then add another bug to deal with the parsing (which does not look like a simple task).
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 2•2 years ago
|
||
Parsing is behind a config value layout.css.has-selectors.enabled
. This
change does not support p:has(> a) combinators, but will handle them
gracefully, just not matching on them.
Comment 4•2 years ago
|
||
bugherder |
Doc updates for this can be tracked here: https://github.com/mdn/content/issues/19572
Description
•