Repository navigation
Switch, FormToggle: Light thumb with sliding 1 and 0 track labels - #86678
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +1.74 kB (+0.02%) Total Size: 8.67 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
|
|
||
| - `--wpds-color-background-thumb-neutral` and `--wpds-color-background-thumb-brand` are now only for the movable handle of a control, such as a slider handle or scrollbar thumb. For the filled portion of a progressbar or meter, use `--wpds-color-background-indicator-neutral` and `--wpds-color-background-indicator-brand` instead. `--wpds-color-background-thumb-neutral` will change to a light color for switch knobs in a future release ([#86584](https://github.com/WordPress/gutenberg/pull/86584)). | ||
| - `--wpds-color-background-thumb-neutral` and `--wpds-color-background-thumb-brand` are now only for the movable handle of a control, such as a slider handle or scrollbar thumb. For the filled portion of a progressbar or meter, use `--wpds-color-background-indicator-neutral` and `--wpds-color-background-indicator-brand` instead ([#86584](https://github.com/WordPress/gutenberg/pull/86584)). | ||
| - `--wpds-color-background-thumb-neutral` is now a light color for switch knobs, where it was previously dark. Anything still using it for a progressbar or meter fill should move to `--wpds-color-background-indicator-neutral` ([#86678](https://github.com/WordPress/gutenberg/pull/86678)). |
There was a problem hiding this comment.
Since @wordpress/theme is externalised, and @wordpress/ui is bundled, this means that an older version of @wordpress/ui rendered in a newer version of @wordpress/theme will render components like Progress with a lighter color, which won't pass accessibility criteria.
@WordPress/gutenberg-components not sure if this is a blocker for this approach.
(Sidenote: also, is it ok that --wpds-color-background-thumb-neutral is lighter than --wpds-color-background-thumb-neutral-weak?)
|
Marking as a draft while I tweak a few details. |
There was a problem hiding this comment.
In my testing, when I omit checked from ToggleControl and press Space, onChange receives true but the track still shows 0. Could we use the input's :checked state for the labels, thumb, and track so the visual state follows the checkbox in both controlled and uncontrolled use?
Also, in the built Storybook's RTL setting, the checked thumb extends past the track and covers the 1. Could we animate inset-inline-start so the thumb follows the same direction as the labels?
|
Code changes LGTM, although the compat issue that I flagged previously is still present; not sure if we can do much about it, though. |
|
@jasmussen I pushed a version that uses a cross/checkmark. What do you think? |
|
For me, this is the key screen to review:
And it's not terrible. It's not as bad as I had worried, insofar as the duplicated symbols could end up adding a lot of noise. The knob is no longer pure white. Can it be? Is there a "strong" variant that makes it light up more? And can this work if the check is the ONLY symbol, that we remove the cross? Neither of these are strong feelings, but they are instincts. I'd love a last quick look from @WordPress/gutenberg-design, and from @JanaMW27. But otherwise, I think we can try this. One completely unrelated thing, and while I'm in preferences:
I don't think the left border works. I recognise the desire to make tabs look alike with just a directional change, but I think the previous vertical tabs read better, and lined up better. |
Previously we were using a background color to indicate vertically selected tabs, but that treatment was odd compared to how other interactive button-like DS ui works. Therefore, for consistency reasons, we made changes in #84572 and #84821:
This is all related to how our "neutral" text tokens can't really get darker on hover/focus (since they're quite dark already in their "resting" state), and how therefore we need a different visual clue to give feedback about hover/focus (see previous conversations in #77153, #81088 (comment), and the work being done in #82294) In other words, if we switched back to using background for selected vertical tabs, we'd lose a way to highlight the selected tab on hover, and I'm not sure we'd have a way to differentiate between a hovered, non-selected tab, and a selected tab. Also, we may actually need to rethink the background anyway, in case the indication for the selected tab needs to meet a minimum contrast threshold. |
Let us please not put the X and ✓ in the toggle, as it's very confusing. The best solution in my opinion is as @jasmussen already saw on Github: adding an indicator besides the switch. It also reduces the visual noise. I also agree that the IO analogy is not clear, and I doubt that it is really needed. |
|
Just to respond to Marco, yes your feedback on the tabs is valid enough, and certainly separate. For me the solution is simple: show a very light active highlight, and just bold the text when it's active, the bold text is the shape change that means the backdrop doesn't have to meet 3:1 contrast. Or add a chevron, or something else. I also understand this makes the vertical tabs visually separate fro horizontal tabs, which I suspect is where the motivation for the change came from. GitHub, to use an example again, has horizontal tabs-like navigation for repos, and vertical tabs in the settings pages. They do have a vertical border there, but it would work even without the vertical border. So for me, the fact that vertical and horizontal tabs look different, that doesn't matter too much to me. But I think I can try a POC PR to explain what i mean. |
@hanneslsm That suggestion won't work for things like iOS has on/off indicators btw, albeit behind an accessibility option. It follows the design proposed here. |
Screen.Recording.2026-11-16.at.10.45.25.mov@jasmussen I pushed a version where check mark and cross now look like they’re printed on a strip that slides with the knob rather than the knob sliding over the track. |
|
I quite like that animation. And while I like the cross and check still, I ultimately defer to Jana, and I also want to note that Hannes' feedback is valid too. Anything stand out as something we want to try? |
|
Jana is away for 3 months so hopefully we can make a decision amongst ourselves.
Which part? |
Okay. But then, I'd suggest using the design as proposed in #86259 (comment) aka putting the checkmark on the knob, instead of the track. As said, I find it confusing that a label/indicator on the track sits on the wrong side. |
|
@hanneslsm placing the indicator on the track seems to be the prevailing convention (see iOS, GitHub, etc.). I'm not married to it though. If there's consensus to put the indicator on the knob that's fine with me but it seems a bit unclear. If you twisted my arm I'd argue:
I don't mind either way, both fix the reported issue :) These seem like details we can easily revisit later... |
Yes, I like that! |
|
Yep, that part. cross or check, or 1/0, or nothing. I still prefer anything we put on the track, because it "obeys the laws of nature", as visible by the nice little animation. But none of this I feel strongly about, so I defer to you and Jana. |
|
Pushed an update to restore the 1/0. Screen.Recording.2026-11-16.at.13.19.41.mov |
d80acf0 to
5982fef
Compare
Gave another look, code continues to LGTM . Looks like we reached design consensus, too. The last item to evaluate is the compat issue listed above (cc @WordPress/gutenberg-components ). Given that the issue doesn't feel critical, and can be solved by updating the bundled copy of Let's give folks a little bit more time in case they wanted to share thoughts on the topic. |
Repurpose --wpds-color-background-thumb-neutral as a light switch knob and add --wpds-color-background-thumb-neutral-disabled. Both switches now use the neutral-weak track when off, a full-height bordered thumb, and show the checkbox check mark in the thumb when on, including when disabled. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…from the off track - Split the knob tokens: `background-thumb-neutral` (off) now maps to the neutral `bg.fgFillDark`, and the new `background-thumb-brand-strong` and `foreground-thumb-brand-strong` color the on knob and its check as the inverse of the brand fill. - Move the off track to `track-neutral` and rename the disabled track token to `track-neutral-disabled`. - Restore the brand stroke on the on knob. Co-authored-by: Cursor <cursoragent@cursor.com>
… track Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…the knob Co-authored-by: Cursor <cursoragent@cursor.com>
Instead of the knob sliding over the label that doesn't apply, the check mark and cross now move with the knob: the label for the new state slides in from the track edge as the other slides out, clipped by the track. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring back the 1 and 0 track labels. Instead of the track changing color, a brand panel now slides with the thumb, which always covers the edge where it meets the neutral half. Each label stays on the same color, so the outgoing label no longer shows grey on the brand track mid-animation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clipping the panel inside the track border left a faint pale ring inside the on track, where the panel's anti-aliased rounded edge met the neutral track. The panel and labels now sit in a layer that covers the border, so the panel's edge meets the page instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5982fef to
796eace
Compare
|
We seem to have general agreement on this so I'm going to merge. Happy to follow up with any tweaks, or to add a token to allow consumer to make the 'labels' optional. |
…rdPress#86678) Co-authored-by: jameskoster <jameskoster@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org> Co-authored-by: yaman-694 <yamanzyan@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: JanaMW27 <janahernandezaraujo@git.wordpress.org>



What?
Closes #86259
Restyles
Switch(@wordpress/ui) andFormToggle(@wordpress/components) following the concept in #86259. The knob is a light, bordered pill in every enabled state, and the track shows a small1when the switch is on and a0when it's off. The labels show in the disabled states too. Follows #86584, which moved progress and meter fills onto new indicator tokens so the thumb tokens could be used for the switch knob.Why?
A disabled switch that's on looks almost the same as one that's off, because "on" is only communicated by the track color and the knob position. The labels make the state readable without relying on color or position (WCAG 1.4.1 Use of Color).
The labels sit on the track rather than in the knob, so the knob's content doesn't change mid-slide. The track behaves like a single surface split between the brand color and the neutral color: the brand fill and the labels slide with the knob, so toggling changes position rather than color. That makes the animation smoother and better preserves the physical metaphor of a switch.
Earlier iterations
This PR first put a check mark in the knob, then tried iOS-style
1and0labels on the track. Joen suggested keeping the labels on the track but using a tiny, thin check and cross, so they read clearly while still feeling like part of the background. After trying that, the PR is back to1and0. The labels first faded in and out under the knob; they now slide with it.FormTogglehad I/O indicators on the track until #23202 removed them in 2020; the problem they didn't solve then, the disabled state, is the focus here.How?
Tokens (
@wordpress/theme):--wpds-color-background-thumb-neutralis repurposed as the knob color of a switch that's off. It's now a light color in light and dark themes alike, where it was previously dark. This is listed as a breaking change in the changelog; progressbar and meter fills already moved to--wpds-color-background-indicator-neutralin Theme: Add indicator color tokens for progressbar and meter fills #86584.--wpds-color-background-thumb-neutral-disabledfor disabled knobs. It follows the theme, so disabled knobs are dark in dark mode.--wpds-color-background-thumb-brand-strongfor the knob of a switch that's on. It's the inverse of the brand fill, so it stays light against the on track.--wpds-color-background-track-neutral-disabledfor disabled tracks.--wpds-color-background-track-neutral's description now mentions switch tracks.Components:
--wpds-color-background-track-neutral, which keeps it distinct from the light knob. The brand fill (background-interactive-brand-strong) is a panel inside the track whose edge always sits under the middle of the knob. It slides with the knob, so the knob always covers the seam and the track never fades between colors. The track border turns brand when on.stroke-interactive-neutralwhen off andstroke-interactive-brandwhen on.1and0are small custom SVGs, 8px square with a 1px stroke, centered in the part of the track the knob leaves exposed. They slide with the knob: as one slides in from the track's edge, the other slides out and is clipped. The1usesforeground-interactive-brand-strong(already a contrast pair with the brand fill) and always sits on the brand fill; the0usesforeground-interactive-neutral-weakand always sits on the neutral track. Disabled labels useforeground-interactive-neutral-disabled.FormTogglethis is a newcomponents-form-toggle__labelselement after the track.inset-inline-startandinset-inline-endrather than atranslateX, with the same duration and easing, so they stay in step and follow the writing direction without a separate RTL rule.Canvaswith aCanvasTextborder (Highlightwhen on), the brand panel and the on track border useHighlight, the labels useHighlightTextandCanvasText, and disabled parts useGrayText.FormTogglemirrorsSwitch. The old transparent-border trick for high contrast mode is replaced by the explicit forced-colors rules.FormToggle's checked and hover styles now follow the input's:checkedstate rather than thecheckedprop, so an uncontrolledToggleControl(nocheckedpassed) shows the right state. Previously its knob didn't move either; the labels made that more obvious.Known issue: light brand colors
With a pale brand color (yellow, for example),
thumb-brand-strongresolves to a dark color, so the on knob goes dark. A solution could be to use colors from the neutral scale for the knob in both the on and off states (as I mentioned in #86259 (comment)), but that would be a larger visual change, so I've left it out of this PR for now.Follow-up
A hover treatment for checked controls (
Switch,Checkbox,Radioand their@wordpress/componentscounterparts) is planned as a follow-up, so they stay consistent with each other.Testing Instructions
npm run storybook:dev.Switch,SwitchControl,FormToggleandToggleControlstories.1shows only when on, the0only when off, and the disabled states share the same track.forced-colors: active) and confirm the knob and labels stay visible in all four states.1.ToggleControlwithoutcheckedand toggle it: the track, knob and labels update.Testing Instructions for Keyboard
Screenshots or screencast
Use of AI Tools
Written with Cursor (Claude) and Claude Code, and reviewed by me.
🤖 Generated with Claude Code