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
docs(Switch): apply review follow-ups from spec audit
Move page intro after DocsPageFeatures per docs.md spec, remove the
misleading HiddenInput "override" recipe, replace the broken thumb
slide animation recipe with a Track background color transition
(Switch.Thumb has inline visibility:hidden when unchecked, so a
translate-x transform cannot visibly slide from the off position),
and add the Enter key parenthetical to the accessibility bullet for
consistency with the checkbox page.
`Switch.HiddenInput` is exported as an internal building block for custom layouts, but auto-rendering via `name` is the only supported form integration path — placing `Switch.HiddenInput` as a child of a `Switch.Root` that already has a `name` will produce two hidden inputs.
147
135
148
136
### Styling with Data Attributes
149
137
@@ -157,13 +145,15 @@ Switch subcomponents expose data attributes for CSS styling without conditional
`Switch.Thumb` applies an inline `visibility: hidden` when unchecked, so the thumb is not visible until the switch is on. This means a sliding transform on `Switch.Thumb` cannot animate *from* the "off" position. Animate the `Switch.Track` background color instead, as shown above.
156
+
167
157
## Accessibility
168
158
169
159
The Switch.Root component renders as a button and handles all ARIA attributes automatically:
@@ -173,7 +163,7 @@ The Switch.Root component renders as a button and handles all ARIA attributes au
173
163
-`aria-disabled` when switch is disabled
174
164
-`aria-label` from the `label` prop
175
165
-`tabindex="0"` for keyboard focus (removed when disabled)
176
-
- Space key toggles the switch
166
+
- Space key toggles the switch (Enter works when rendered as button)
177
167
178
168
For custom implementations, use `renderless` mode and bind the `attrs` slot prop to your element:
179
169
@@ -197,9 +187,9 @@ Use `Switch` for settings that take immediate effect, like toggling a feature on
197
187
198
188
`Switch.Root` only renders the hidden native input when a `name` prop is set. Without `name`, the switch is purely visual and won't appear in `FormData`. Add `name="myField"` (and optionally `value`) to participate in form submission.
199
189
200
-
??? How do I animate the thumb sliding?
190
+
??? How do I animate the switch state change?
201
191
202
-
Apply a CSS `transition` to `Switch.Thumb` (or `Switch.Track`) and use the `data-[state=checked]:` variant to change its transform. For example, `class="transition-transform data-[state=checked]:translate-x-5"` slides the thumb when toggled. No JavaScript event handling is needed — the data attribute flip drives the animation.
192
+
`Switch.Thumb` applies an inline `visibility: hidden` when unchecked, so transforms on the thumb cannot animate from the "off" position. Apply a CSS `transition` to `Switch.Track` and use the `data-[state=checked]:` variant to change its background — for example, `class="transition-colors bg-gray-300 data-[state=checked]:bg-primary"`. No JavaScript event handling is needed — the data attribute flip drives the animation.
203
193
204
194
??? Can I use Switch.Root without the Track and Thumb subcomponents?
0 commit comments