Switch
Switch is an on/off toggle: a native <input type="checkbox" role="switch"> drawn as a track and thumb, wrapped in a
<label>. Use it for a setting that takes effect as soon as it flips, without a submit.Forms
When to use
Use when
- Turning an immediate-effect preference on or off (notifications, dark theme).
- Each row of a settings panel controls one independent boolean.
Avoid when
Usage
<Switch name="wifi" label="Wi-Fi" checked={wifi} onChange={(e) => setWifi(e.target.checked)} />Sizes
<Switch size="small" label="Small" />
Each size reads theme.component.switch.size.<size> (trackW, trackH, thumb, pad, in px); override one field
with createTheme({ component: { switch: { size: { medium: { thumb: 20 } } } } }).
Color and locked state
The on track uses color (default primary); a validation variant (success, error) wins over it. A locked
Switch (checked and disabled) keeps the thumb on but sits on the muted disabled fill.
<Switch name="beta" label="Beta" color="success" /> <Switch name="email" label="E-mail confirmed" checked disabled readOnly />
Accessibility
- Screen readers announce a switch with an on/off state;
Tabfocuses it andSpacetoggles it. - Keyboard focus draws a
:focus-visibleoutline around the track, kept in forced-colors mode. - The wrapping
<label>names it fromlabel; with no visible label, passaria-label.
Properties
Name
Type
Default
Description
color"primary""secondary""tertiary""information""success""warning""danger"'primary'Interaction palette of the checked state (fill / ring / ink). Defaults
to the brand `primary`, like `Button` and `Tabs`. `variant` (`success` /
`error`) still wins when set.
labelReactNodenoneText or element shown next to the control. When a `string`, it is
rendered via `BaseText`; when a `ReactNode`, it is rendered as-is.
labelPropsPartial<TextInterface>noneTypography overrides for a string `label` (`fontSize`, `color`, …).
Ignored when `label` is a `ReactNode`.
@example ```tsx
<Switch name="wifi" label="Wi-Fi" labelProps={{ fontSize: 'micro', color: 'ink.secondary' }} />
```
onChange((e: ChangeEvent<HTMLInputElement, Element>) => void)nonesize"small""medium""large"'medium'Size of the control (track + thumb).
valuestringnonevariant"success""default""error"'default'Visual variant of the input — reflects the validation state.
Placement props (area, alignSelf, justifySelf) apply to the label wrapper.