-
Notifications
You must be signed in to change notification settings - Fork 708
CSS Toggles Proposal #6991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you thinking of this video? |
No, I wasn't it had slightly different content as the purpose of the
meeting was to think about how those 3 ideas aligned, or didn't, etc.
I didn't share that one because I didn't want to ask people to watch 2 videos, and that one is less complete. That said, it's still a good video if we can't find the other, I guess.
|
I'm actively working on an explainer and (js-polyfill driven) demo to provide more details around this proposal. |
Great proposal! It would be great if the concept of "element state" could also have an intuitive interface across HTML / CSS / JavaScript, such that HTML could define these states with simple attributes (other than just in the |
I've been thinking about this proposal a lot (as my CSS nerd brain often does). I'm simultaneously super-excited about it and also concerned that it is not "broad" enough. What I MeanSo, what this proposal effectively does is achieve (part of) something that HTML authors have failed to do thus far, at least making it to the browser, which is to natively be able to create "instances" of elements that are data-bound and stateful. This lack of "templating" has, of course, meant that this is been replicated ad nauseam in user land (e.g. React, Vue, Svelte, Angular, you name it). On the one hand, CSS is a logical place for this functionality, because the abstraction of classes / selectors from elements means that you can create "instances" of this "toggle state" as an extension of the language. But this type of state is not necessarily presentational or only presentational. Therefore, I can see a scenario where:
Now, of course, the explainer addresses this directly! Saying (under Non Goals):
I get it. This group is addressing the needs of CSS, and not wanting to expand the scope beyond presentational. I guess what I'm wondering if there has been any discussion / exploration around something like a Maybe this just isn't possible at the moment, without the ability to create instances of HTML partials (Something like https://github.com/WICG/webcomponents/blob/gh-pages/proposals/Template-Instantiation.md). So maybe CSS is the only way to put this idea of "state" tied to "instances" in a declarative way. The idea of CSS being stateful (where the value is not a static value in the document) is just somewhat novel, so it feels like it could be more abstracted across the whole HTML/CSS/JS platform. 🤔 But I don't have any good alternative pitches, so I don't know. Events and stateThe other mild concern I have is that what causes a state change is implicit and not explicit. This seems to be addressed in the explainer under Other Component Interactions. I agree that something other than just Some questionsBy the way, what happens when a state root "definition" gets redefined by a class that's added after that state value has been "triggered"? Especially if the number of states is now different, or the current state value is no longer valid, according to the toggle-root? Would it always reset? What if the current state value is valid but is in a different "position"? CSS is good for abstracting element definitions in some ways, but the cascade model means that "current state of X element" could be hard to reason about. I searched the explainer for "cascade" or "overrides" and couldn't find anything that addressed this directly. Final thoughtsJust to reiterate, I think this is in general a really good idea! It's possible these other state concerns could be ironed out by some future HTML feature that would be 100% compatible with this. I just think it's worth thinking about it in broad (web platform) terms. |
The underlying mechanism here is to give elements a (deliberately very simple!) notion of "state", which can be created, manipulated, or reacted to by JS, and then have (a) a way for user interaction to change that state without script (the This state is intentionally kept to just a non-negative integer or an ident; CSS can't reasonably handle much more than that with its syntax, on either the setting or reading side. To the extent that other systems can work under that limitation, they're free to use a toggle to store stuff on an element. If they're not using at least one of (a) or (b) above, tho, there's not really any benefit to it; just storing info in a JS property on the element is equivalent, more powerful, and more convenient. This is very intentionally not a generic whole-app state management system, as that is a far more complex problem and ties into far more things than CSS can interact with. It's just one corner that is useful on its own, and can form a useful appendage of larger state management systems.
Spec will get cleaned up as we progress, and I expect it will grow more ways for users to interact with a toggle (like tying it to scroll snaps!), but the default is going to be "interaction" as defined by the host language. HTML already has activating an element as a well-defined concept.
Nothing. At style resolution time we check that every element with a |
@tabatkins That makes sense! I trust y'all have done deeper thinking on this than I have. Thanks for those explanations.
Oh interesting. 🤔 It would still be a useful thing to call out in the explainer, how that behavior works. |
Minutes from CSSWG discussionFriday, September 16th, 2022 |
I'm not putting a spec since there isn't one in the wg yet, but on today's call @tabatkins introduced a proposal for comment and consideration that he's been working on for some time, but has recently had some fresh thought and interest. He asked if we could look at it and discuss perhaps next week and said that the chrome team was interested in doing some prototyping soon.
https://tabatkins.github.io/css-toggle/
As this has been developing for some time, there has already been a non-trivial amount of discussion and I'd like to have an issue for this where we can link up some of those as people consider it.
Notably, part of the reason this came up again recently is some adjacent work and needs - as such there were 2 breakout sessions at TPAC on joint topics of the work in 'tabs' in openui, Microsoft's focusgroup proposal and this. Unfortunately the I cannot find a video of the presentation @travisleithead gave as well but the slides are available in https://www.w3.org/2021/10/TPAC/breakouts.html#focusgroup-1 and the minutes of 1 of those sessions at least are in https://www.w3.org/2021/10/21-focusgroup-minutes.html#s1 ... I feel like the minutes exist for the other one too, but I don't have a link handy at the moment.
The text was updated successfully, but these errors were encountered: