Switch
Toggles a single setting on or off, with optional icons in the thumb.
import { Switch } from '@windmorph/react';Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the switch, and on to the next element. |
| Space or Enter | Switches it on or off. The thumb grows while the key is down, and the switch changes when the key is released. |
A native checkbox toggles on Space only; the switch adds Enter, as M3 asks for both keys.
Screen reader
- Role
switch: a visually hidden native<input type="checkbox">withrole="switch"(React AriauseSwitch), so forms and assistive tech work natively.- Accessible name
- Its label (
children), oraria-label/aria-labelledbywhen there is no visible label. The types require one of the three. - States announced
- On or off (
checked), disabled, read-only (aria-readonly) whenreadOnlyis set, required (aria-required) withrequired, and invalid (aria-invalid) withinvalid.
The thumb, its icons (icons, checkedIcon, uncheckedIcon) and the state layer are decorative and hidden from assistive tech (aria-hidden).
Focus
- It is in the Tab order where it sits in the page. A disabled switch can't be focused; a read-only one can be focused but not changed.
- Keyboard focus shows M3's focus indicator around the track: a 3px
secondaryoutline 2px outside it, and the thumb takes its hover colour. Pointer presses show no ring.
Touch target
- The track is 52 × 32px. An invisible
TouchTargetmakes its hit area 52 × 48px without changing the layout, and the whole<label>, text included, toggles the switch. density(or the theme's) only shrinks the state layer around the thumb, 40px to 32px; the track and the 52 × 48px target stay.- Switches you stack yourself need their rows 48px apart, top to top, so two targets never overlap: 16px between the 32px tracks (
gap-4) at every density, or use aListof switch items.
Motion
Under reduced motion the thumb jumps to the other end and changes size at once; its colours still fade. The press ripple appears at full size without growing. Pressing or dragging snaps the thumb in every mode.
What you need to do
- Give every switch a name: visible
children, oraria-label/aria-labelledbywhen the label is elsewhere. - Keep the label the same in both states (Wi-Fi, not Wi-Fi on / Wi-Fi off); the switch announces its own state.
- Use a switch for a setting that takes effect at once. For a choice submitted later with a form, or one that needs an indeterminate state, use
Checkbox.