-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
<input type=checkbox switch> #4180
Comments
Shouldn't this be a checkbox with a different style? E.g., cc @whatwg/rendering |
Definitely makes more sense as we get backwards compatibility. |
Apologies for not welcoming you by the way, I missed this is your first issue. Belatedly, welcome! https://whatwg.org/working-mode#changes and https://whatwg.org/faq#adding-new-features provide some context for the way work is done. I think for this particular request there is enough to go on as this is clearly an established UI widget that makes sense to expose the web in some form. Thanks for raising it. |
Indeed, welcome. I'm glad @annevk pointed you to the adding new features FAQ, as it helps keep specific solutions (e.g. Coincidentally we have been having some discussions internally in Chrome about better built-in UI widgets and form controls. At this point I don't have much to report beyond tentative interest in the general program. But there's a lot to still figure out in the specifics: e.g. theme-ability, whether we can do this in a layered way that does not require more browser magic (like |
👍 It also seems worth mentioning that ARIA (since ~1.1 I think) now has a |
I am happy to work with the team if any help in needed in getting this spec'ed or implemented, in whatever form it makes sense to get a toggle switch control into the browsers. I will be careful about not having a solution but only a problem in the future. |
@sideshowbarker that's very interesting, that almost suggests there is some semantic related to the presentation of a switch checkbox. Using a CSS property at that point wouldn't work well as that couldn't map to ARIA cleanly. cc @whatwg/a11y |
The ARIA 'switch' role maps to the accessibility APIs, so an element with 'role="switch"' has semantic meaning to screen readers.
|
I don't think this is a bad idea, but proposals for new browser features can take a long time between conception and implementation across platforms—assuming universal adoption is ever achieved. Because of this, the question that immediately springs to mind for me is "what does a reliable non-JavaScript fallback pattern look like for this?", and |
I agree that's a good consideration, but note that |
Good point @annevk. I can't see any reason why that wouldn't work as well! |
There seems to be no progress on this issue for some time. Is there any way I can help? |
@tkent-google @cdumez @hober @smaug---- is this something you'd implement if specified? @atishay apart from getting the above question addressed (implementation interest), we'll need someone to make the relevant changes to the standard and write tests. I suspect a new boolean attribute named |
Sounds reasonable. When spec'ing this, need to be very careful with styling related properties. Why we'd disable the intermediate state? I'd rather try to keep the behavior on JS side as close to checkbox as possible. |
Chrome would prefer to not perform a new quick-fix for this, e.g. adding an attribute. We'd instead prefer to work on it more holistically as part of a general question of how to add new form controls and behaviors, in a way that does not involve magic that only browsers could do today (such as adding a new attribute to (Side note: as a benefit, our preferred approach should entirely determine the styling interactions, helping with @smaug----'s concern.) More concretely, we'd prefer to see something implemented in JavaScript/custom elements/Houdini/AOM/ElementInternals/etc., and then put into the spec in a way that is indistinguishable from such a solution. If that's not possible today (e.g. due to missing foundational pieces) then we'd like to delay committing to a solution in the spec. Our suspicion is that this will not be possible today, but for those interested in making progress, Chrome's preferred avenue would be to attempt to do so with today's technologies, and see where the gaps are, exactly. All that said, I would not count this as "strong opposition", so if there are multiple other independent engines who want to add form controls in the usual magic-using way, that would be fine to land as part of the WHATWG progress. Chrome just would not prioritize following such an implementation, as we'd rather commit those resources to working through the general problem space of allowing the set of form controls to be extensible/themeable/polyfillable/etc. |
I looked at the various ways to create custom element to do this task. Here are some issues that we would face with Custom Elements:
The documentation is scant on custom elements and I am not sure if I missed anything. If needed I can provide a Codepen for approach 2 or 3. @domenic A form element to have a shadow DOM would be required for a clean implementation. It could associate the Another way, this could be spec'ed out is to allow Shadow DOM to |
@atishay We're standardizing "Form-associated custom elements", and Chrome Canary has it behind a flag. Please refer to WICG/webcomponents#187 (comment) |
Thanks very much for the exploration, @atishay! Indeed, as @tkent-google mentions, the form-associated custom elements feature would be a crucial building block for this sort of work, I think. We'd love for you to try it out and see how well a switch control built on that works out. Another approach worth considering is using CSS custom paint (customizing an |
I have a basic version of switch using custom elements here: https://codepen.io/atishayjain/pen/XoEQXN?editors=1010 This is not very customizable and I can make a version which is much more dynamic if that helps in standardization. This is not backwards compatible with checkbox. If needed, I can try the custom paint approach, which could behave like |
Is there something else that can be done to get some progress in getting a toggle switch element? |
@domenic Do we need anything else? Is there still interest in building something in this area? |
Google is going to propose standardizing the switch form control as a JavaScript Standard Library. Here is an initial explainer: https://github.com/tkent-google/std-switch/blob/master/README.md |
@tkent-google That's pretty cool thanks for sharing. I agree with @domenic statement here. As such, I think we should take this a bit further in a few different ways as I think there a few key pillars to the problems that web developers face with regard to the native controls on the web, some of which you have issues open for so I'll focus those discussions on those. One thing that I believe we should allow is for built in components to not require the dash. So in this case, we wouldn't have Additionally, while I think this can be done in a stepping stone fashion, I don't think the author should be required to |
The dash question is an interesting one. We've briefly discussed it in another context at WICG/virtual-scroller#161. Maybe we should open an overall issue. Similarly, we're very interested in exploring a future built on Apple's JavaScript standard library proposal where new high-level features can be opt-in imported, instead of every page paying for every new web platform feature we add forever. As noted in that issue, the two design choices are connected and synergize with each other. |
I opened a WICG thread for this. https://discourse.wicg.io/t/proposal-a-toggle-switch-control-element/3620 |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'd encourage people to continue their discussion of Safari's implementation on the Safari bug tracker, not on the HTML Standard bug tracker. |
…auto https://bugs.webkit.org/show_bug.cgi?id=267334 Reviewed by Aditya Keerthi and Tim Nguyen. Per discussion in whatwg/html#4180 we do not want styles intended for appearance:auto to leak into appearance:none. Ideally we pay more attention to this with all form controls going forward, but that is a much larger undertaking. * LayoutTests/fast/forms/switch/display-expected.txt: Added. * LayoutTests/fast/forms/switch/display.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/rendering/widgets/input-checkbox-switch.tentative.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/rendering/widgets/input-checkbox-switch.tentative.window.js: * LayoutTests/platform/ios/TestExpectations: Enable WebKit-specific switch tests on iOS too, except for those that currently do not work. * Source/WebCore/css/htmlSwitchControl.css: (@namespace "http://www.w3.org/1999/xhtml";): (input[type="checkbox"][switch]::thumb, input[type="checkbox"][switch]::track): * Source/WebCore/rendering/RenderTheme.cpp: (WebCore::RenderTheme::adjustStyle): (WebCore::RenderTheme::adjustSwitchStyleDisplay const): (WebCore::RenderTheme::adjustSwitchStyle const): (WebCore::RenderTheme::adjustSwitchThumbOrSwitchTrackStyle const): * Source/WebCore/rendering/RenderTheme.h: * Source/WebCore/rendering/RenderThemeIOS.mm: (WebCore::RenderThemeIOS::adjustSwitchStyle const): No longer skip most of the iOS style adjusting logic for non-auto sizes. Canonical link: https://commits.webkit.org/273078@main
I apologize for not knowing enough about the scope of the HTML specification. |
(I decided to reply to #9546 (comment) here as this reply doesn't really pertain directly to the contents of the PR. And I generally prefer open-ended discussion to happen in the issues.) Hey @chrishtr, good to know we're largely in agreement. We would certainly like to have more definitive answers for styling form controls as well and we hope that if we all prioritize that somewhat we can make a dent in the coming years. Now given your response there's a couple things I wanted to note:
I hope we can make meaningful progress together on all this soon and figure out a larger plan around stylable form controls. Thanks! |
A switch does have a higher bar than a checkbox, yes. There's significantly more variation in styling of existing hand-rolled switch controls than there is with a checkbox, and the internal structure is meaningfully more complex. It's nearly the complexity of a range input, which does indeed trigger exactly the issues Chris is worried about (authors ignoring the built-in because it's ugly in its base form, and insufficiently styleable to fix).
Do you have any styling concerns about |
Commenting here as follow on to being mentioned in the other thread, and the Webkit bug I had filed. The a11y concern with the current state of the switch proposal is how to treat or explain the accessibility implications of authors adding custom CSS pseudo content to styled switches. The text that authors would add to a switch in this manner is not typically representative of its 'label', but rather text / revised text, or a graphical representation of the switch's state. E.g., "on" or "off" being a typical visible representation of the way the switch is communicated to people using screen readers, for example. But where there is presently a gap is how 'custom states' might be conveyed to people. E.g., a switch that displays text in its track of 'light' or 'dark', where the designer's intent is that those are the states they want the switch to convey to people, but a user who would interact with such a switch would continue to hear "on" and "off".
The webkit bug i filed became an issue about how the alternative text for the pseudo content had a bug, so marking it as decorative wasn't working, and thus the pseudo content was being used to name the switch, since none of the demos had labels. While that was a bug that became apparent because of the unlabelled examples, making the alt for pseudo content work properly doesn't resolve the above where one might want the visible pseudo content that represents the custom 'states' to be conveyed - but it would still be inappropriate to convey it as the 'name' of the switch. We have been discussing this exact issue in Open UI, and the subsequent issue I filed in ARIA in how this use case might be supported. A potential solution that was discussed was having companion attributes in HTML to allow authors to express what state they'd want communicated, rather than the default on/off. (the reason companion attributes in HTML was brought up is because while ARIA could arguably create the attributes to do this - ideally developers shouldn't have to use ARIA to make default HTML elements fully accessible. So we would like to see this solved in HTML, rather than as an extra feature/band aid someone would need ARIA for). Making them attributes would mean that then CSS pseudo content could still leverage the text, allowing devs to continue to style the way they are now. But it'd take the strings out of CSS and into HTML, where then those attributes could be exposed to the accessibility tree, and would allow for arguably easier localization by developers.
If someone has a different proposal to accommodate this use case that wouldn't need these attributes, then awesome. Would love to hear it. But without accounting for that / how to make the custom states accessible to more than just people who can see, i would expect some strong guidance informing authors to not provide custom states in this way, and also guidance on how to craft labels for their switch controls that would lend themselves better to the on/off states the control communicates. E.g., "Enable dark theme" where hearing on/off would make more sense, instead of just "theme" where on/off is insufficient and the visible pseudo content is necessary to understand what on and off even mean. If state could be communicated via the attributes I mentioned (bikeshed away) then the 'descendants' of the switch could arguably just be hidden from the a11y tree. If not going in that direction though, then again would expect guidance to emphasize the importance of not relying on pseudo content to convey information about the swtich - and how if a switch goes unlabelled (already should be a no-no....) then the pseudo content could contribute to the name of the control, or not, depending on if decorative CSS alt text was applied to the pseudo content... and honestly, devs will often miss this detail... |
I wasn’t sure whether to comment on the PR or issue myself; discussing non-PR review items further here makes sense to me.
Definitely! We all agree I think that customized styling of built-in form controls, but without losing all of the other benefits of those built-in controls, is an important developer need (and has been for a very long time).
The issue can definitely be confusing (at least for me). In fact, I discussed it at length with him yesterday to make sure I understood it fully, and I think I understand it well now. What Joey is saying there is that we won’t be able to change the UA style sheet in response to different values of Stepping back / orthogonally to the above point, let me describe what I/the DOM team mean by a “styleable form control”. It’s a form control that has a mode where:
Currently, websites often use In the case of
I agree that this should be worked out, thanks for filing that issue and let’s discuss more there.
I’m not sure how this is applicable. The
I agree these should progress. We'll actively engage with these issues, but we'll need WebKit folks to help drive them to consensus.
Mason was suggesting alternate designs in those cases (e.g. using an attribute to opt-in, rather than a CSS property), in part to address possible drawbacks or complications of a CSS property. To reiterate, I (and Joey in his comment referenced above) are saying we think that approach (the appearance CSS property) would work fine for select and we’re ok with it. Joey is now prototyping a complete implementation.
I agree 100%. The main aim of my comment was about shipping, not about the viability of different proposals. I’m glad we are collectively making progress on this area, since it’s important to developers that we help them solve this problem. I think the web will be much better off for our efforts! |
I don't think we're in agreement that changing And also, it was at least our understanding that |
Some thoughts (that may be better as a separate issue?) from an architectural point of view: It’s a pretty common problem that authors want to style controls in a way that looks dramatically different, even though the underlying semantics and API don't necessarily change very much (or even at all). A few examples:
So how could things like these be addressed?
So it seems that an attribute might be the better approach here, but not ad-hoc attributes like |
You make a good point that we need to make sure it works for a variety of form controls, looks ok by default, and be easily customizable. To that end, I worked with @argyleink to explore that for several controls and commented here with our results. It looks feasible to me to do so without changing UA styles for input or select, with the default output looking fine and accessible by default. |
What do you mean by "the DOM team"? People who work on the DOM Standard? Surely that includes @annevk. |
I meant the Chrome DOM team. Apologies for forgetting the qualifier. |
Given that Safari 17.4 shipped |
Hey @pepelsbey! There's a PR for this feature over at #9546 but there's disagreement over to what extent it needs to describe rendering-related requirements. WebKit's opinion is that it's sufficient to say as much as way for other form controls (which is to say not much) whereas other engines prefer a higher bar. I looked into that and the higher bar essentially requires solving it for most form controls as they are all rather similar in their opaqueness which makes it a bit of a tall order. And we also haven't gotten engagement on the related CSS WG issues to solving that (despite assurances to the contrary above), putting it all in a bit of limbo state unfortunately. |
I'm not sure that's required here, since this is a brand-new control. There shouldn't be compat issues.
The last conversation that I'm aware of was the Sept 19 TPAC meeting, at which Apple said there was a forthcoming specific proposal that needed "1 month of legal review" and then would be made public. If we missed the publication of this proposal, awesome - can you please provide a link? I had been assuming it'd get linked on w3c/csswg-drafts#10866. Chromium is very much supportive of solving the general form stylability problem, so it'd be unfortunate if there's been a miscommunication. |
It's not about compatibility issues though. It's about deciding which properties apply and do not apply for @mfreed7 I'm not sure what you mean. @chrishtr post above cites a number of CSS WG issues I brought up that lack replies from Google and Mozilla and we were told we would get replies on. The problem here is not |
I didn't cite them, I just quoted your comment listing them. I do still agree it would be good to make progress on them. Just enumerating them and suggesting next steps: For w3c/csswg-drafts#9830 my suggestion is for you to propose names and Agenda+ the issue, since bikeshedding like that is best done in WG calls. I've Agenda+'d it. For w3c/csswg-drafts#9825 is quite broad, do we need to do anything for that or is 9830 sufficient? For w3c/csswg-drafts#9832 I'm not sure and a good next step is to ask the CSSWG for feedback. I've Agenda+'ed it. For w3c/csswg-drafts#4410, is it relevant to checkbox switch? |
Oh right, I'll blame that on not being a native speaker. You missed w3c/csswg-drafts#10039 which I think is the most relevant as the other issues are more about The range-related issues can probably be ignored for now in favor of 9830, although I suppose it really depends on how we end up deciding on the pseudo-elements and what they need to be consistently named with. |
Ok. It looks like you asked two questions when filing that issue, which Mason answered in order to unblock your proposed path to specifying them from my perspective. |
This is a feature request on the behalf of all web developers targeting mobile. Here are reasons the toggle switch element should be natively available in HTML forms:
I am happy to help writing a spec for the
<input type="switch" />
element if that can help getting it into the browsers.The text was updated successfully, but these errors were encountered: