You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The major drawback is that we can no longer style the <label> elements, which are not siblings of the <input> elements in the above structure. Moving the labels into the <task-list> also does not make sense. Arguably, the <input> elements do not belong there, either. But because we are hiding them, it's only structurally inconvenient.
Being unable to style the labels is a showstopper for filtering with pure CSS for now.
CSS4 defines a :has() selector, which can select an element based on properties of its descendants. A document structure like we have today can implement filtering with it, without depending on JavaScript:
This bit of magic lets the selector for main reach into the <fieldset> to find which radio button is checked. The fieldset and radio buttons live in a different tree from the <task-item> elements that we want to hide. It allows our document structure to remain structurally sound.
The :has() selector currently has only experimental prototype support in Chrome. It is not usable today.
Status update: :has() is now supported everywhere that matters as of April 2024. I want at minimum one year of the feature in the wild before the app depends on it.
Since Firefox 121 introduced support in December 2023, I wouldn't want to make this change until at least December 2024.
The anticipated release date for this is December 2024. At that time,
the `:has()` selector will have been available in the wild for at least
1 year on all major browsers.
- Closes#1
The filter buttons currently work by setting a data attribute on the
main
element in JavaScript:task-webapp/index.js
Line 52 in efe6801
This was necessary because, as far as I can tell, there is currently no way to do this filtering in CSS alone.
CSS selector syntax operates on a node hierarchy. So it is possible to do this kind of filtering when an ancestor has a specific attribute:
task-webapp/index.css
Lines 96 to 104 in efe6801
Selecting elements based on properties of siblings is also possible. E.g. a DOM with this structure:
Where
<task-item>
elements are appended to<task-list>
can do the filtering with the following CSS:The major drawback is that we can no longer style the
<label>
elements, which are not siblings of the<input>
elements in the above structure. Moving the labels into the<task-list>
also does not make sense. Arguably, the<input>
elements do not belong there, either. But because we are hiding them, it's only structurally inconvenient.Being unable to style the labels is a showstopper for filtering with pure CSS for now.
CSS4 defines a
:has()
selector, which can select an element based on properties of its descendants. A document structure like we have today can implement filtering with it, without depending on JavaScript:This bit of magic lets the selector for
main
reach into the<fieldset>
to find which radio button is checked. The fieldset and radio buttons live in a different tree from the<task-item>
elements that we want to hide. It allows our document structure to remain structurally sound.The
:has()
selector currently has only experimental prototype support in Chrome. It is not usable today.The text was updated successfully, but these errors were encountered: