-
Notifications
You must be signed in to change notification settings - Fork 7
Switch syntax from :state(foo) to :--foo #6
Comments
Ultimately this comes down to aesthetics. I like
The first is probably the most important consideration here. Maybe it's possible to change shadow parts to use Regarding non-boolean states, as long as it's an enumerated set of values and not an open-ended set, it could be transformed into set of distinct states. For example, let's say a I think there's actually more of a use case for shadow parts to be parameterized than custom states. For example, a list-type control could expose a shadow part for each list item, where the set of list items can be any number. But it's harder to imagine a non-boolean state that isn't equivalent to an enumerated set of boolean states. |
I think this might just be your own authoring experience, and perhaps lack of authoring familiarity with modern custom stuff in CSS, talking? A lot of people used to be uncomfortable with And custom properties are just the start here. Custom MQs will be
And now talking about alignment, this is where the distinction gets important. If we'd done If we'd used So, yes, in an ideal world ::part() could have been done as a
CSS has a whole bunch of them? Every functional pseudoclass that currently exists in CSS is not an enumerated set. |
Agreeing with Tab, and expanding a bit. This change isn't about aesthetics, I actually think ':state(foo)' is prettier than ':--foo', this change is about turning this feature from a narrowly scoped special pseudo class to a general purpose custom pseudo-class, bringing custom elements that much closer to being able to do what native elements can. ':state(foo)' also stutters, pseudo classes are fundamentally all about exposing state, calling it state yet again adds nothing. We would never have done ':state(hover)' or ':state(visited)'. (This excludes the pseudo classes that are selector math, which are arguably something completely different and, given a time machine, would have a different syntax, just like pseudo elements do.) I also want to point out that I explicitly stated a desire for this to be brought into alignment with shadow parts, by changing '::part(foo)' to '::--foo', but that's a different topic with its own set of concerns, and I'll address those elsewhere. Non-boolean states is also a separate issue, which I also raised multiple times, and will be addressed elsewhere, let's not overload this issue. But there are existence proofs for the need for non-boolean state. Of course in theory all states can be expressed as a series of booleans, that's the foundation of digital computers. That doesn't mean the combinations don't get out of hand rapidly or are the most friendly to authors. |
@tabatkins I don't see any example of how the state would be declared, so want to confirm that it would be element.attachInternals().states.add("--foo"); and not element.attachInternals().states.add("foo"); That is, the Aside: if the above is correct, then this change would open up the possibility of eventually setting built-in pseudo-classes via |
Yes, it would require using the full name, including the dashes, just like with all the custom property APIs. |
I suggest just taking this to a vote at the CSSWG. I've asked to put this on the agenda for next week. |
This was brought up in the Web Components meeting, and while we didn't consider it a blocker, it was considered a reasonable objection. Jan brought up a possibility to fix this: w3c/csswg-drafts#4900 |
Minutes of Web Components meeting
|
I’d expect custom pseudo‑classes (e.g.: |
I'm actively needing to add custom state to a component, and while this is a valid point by @tabatkins I wanted to discuss it a bit further since I missed the F2F discussion of this.
I'm curious if we play this out a little bit with real examples. I'm working on a I'd much rather have:
And yes I know that most CSS authors will recognize that
We could possibly create a clear definition of state for the web platform and alias CSS functions to relevant Sorry for the long thread and hopefully my stance is clear. |
Note that Jan expressed similar sentiment at first but came around:
In other words, give it a little time, you might come around from your initial dislike too. ^_^
Apologies, but I'm not sure what you're arguing for here. Could you elaborate? |
Thanks Tab, and sorry if that last part got confusing. Hopefully this will make it clear:
So the recommendation that it sounds like everyone is landing on is to have state change to use
Thanks! |
<--my-foo></--my-foo> Since the tag name selector checks for exact name, unless you intend to make it check for |
Yeah, custom element names go by the HTML rules, which are just "must have a
And more directly: the hint is that there's a |
I'm solely popping in to say that I don't have a really compelling reason outside of aesthetics and so if most people are for this change then let's do it. |
If we go with this.attachInternals().pseudoClasses.add('--foo') ? |
I personally think that Custom States and Custom Pseudo‑Classes should be separate, since my expectation is that Custom Pseudo‑Classes are controlled by the page, whereas Custom States are controlled by the element. |
RESOLVED: Syntax changes from :state(foo) to :--foo Minutes of the CSSWG meeting
|
(The CSS Virtual face-to-face just had a discussion that should have been posted to WICG/custom-state-pseudo-class#6.)
Given this resolution, could CSS WG please take up the corresponding issue for CSS Shadow Parts? It looks like consistency was discussed but deferred to a separate discussion? |
Yup, that's my plan shortly, it was discussed tangentially during the topic. |
* Change the syntax; :state(foo) -> :--foo Fixes #6
This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd
This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd
This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#845429}
This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#845429}
This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#845429}
…ntax, a=testonly Automatic update from web-platform-tests Custom state: Update the pseudo class syntax This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#845429} -- wpt-commits: 444e9de5e00d00cdc01aaf9197c6c53d7720945a wpt-pr: 27229
…ntax, a=testonly Automatic update from web-platform-tests Custom state: Update the pseudo class syntax This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <futharkchromium.org> Commit-Queue: Kent Tamura <tkentchromium.org> Cr-Commit-Position: refs/heads/master{#845429} -- wpt-commits: 444e9de5e00d00cdc01aaf9197c6c53d7720945a wpt-pr: 27229 UltraBlame original commit: 9777af6b9c0fb69c1a3b70e2414b09565cf191b5
…ntax, a=testonly Automatic update from web-platform-tests Custom state: Update the pseudo class syntax This CL updates the custom state pseudo class syntax from :state(foo) to :--foo. See WICG/custom-state-pseudo-class#6. This feature is not shipped yet. Bug: 1012098 Change-Id: I71bd92113d89b073cdeba3b6ab78d2c7f0e091dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636075 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#845429} -- wpt-commits: 444e9de5e00d00cdc01aaf9197c6c53d7720945a wpt-pr: 27229
(The CSS Virtual face-to-face just had a discussion that should have been posted to WICG/custom-state-pseudo-class#6.)
This was raised by @plinss in the CSSWG discussion last week.
The point of the state pseudoclass is to expose a class-like semantic via a pseudoclass. It's currently "namespaced" under the
:state()
function to avoid collisions with other pseudoclass names. However, the way we've avoided such clashes in other places in CSS is by just using the --ident pattern, which is by convention reserved solely for author-defined names.Peter suggests that it would thus be more natural to expose this feature with that syntax, so that instead of
:state(foo)
, you'd write:--foo
. I agree with this!:--foo(bar)
, exactly like the non-boolean UA pseudo-classes, rather than the imo less readable:state(foo bar)
, or a novel syntax like:state(foo = bar)
.A practical consequence of this is that we'd need to add a check to the .add() and .toggle() methods to ensure that the token being set starts with a "--", so we can throw otherwise. (This is the standard practice in similar APIs, to ensure a close concordance between all uses of the identifier, rather than accepting anything and implicitly prepending a "--" for CSS use.)
I believe the parsing difficulty is similar, but I'm not familiar with the impl details.
The text was updated successfully, but these errors were encountered: