Switch
A toggle control for switching between on and off states.
Import
import { Switch } from '@matix/components/switch';Usage
With Label
<Switch label="Wi-Fi" defaultChecked />
<Switch label="Bluetooth" />
<Switch label="Dark mode" defaultChecked />Description
Add description for helper text under the label. The switch gets the label as its accessible name and the description as its accessible description, through aria-labelledby and aria-describedby.
Use description for a settings row. Use Field for a text control with a label above it.
Disabled
<Switch label="Disabled off" disabled />
<Switch label="Disabled on" disabled defaultChecked />Custom Styles
import * as stylex from '@stylexjs/stylex';
const custom = stylex.create({
wide: { width: '56px' },
});
<Switch sx={custom.wide} label="Wide switch" />;API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Label rendered next to the switch |
description | ReactNode | — | Helper text under the label. Becomes the accessible description |
defaultChecked | boolean | false | Initial on/off state (uncontrolled) |
checked | boolean | — | Controlled on/off state |
onCheckedChange | (checked: boolean, event: Event) => void | — | Called when state changes |
disabled | boolean | false | Disable the switch |
sx | StyleXStyles | — | StyleX style override |
All other props are forwarded to the underlying Base UI Switch.
Accessibility
- Wraps Base UI Switch — renders with
role="switch"andaria-checked. - Label is associated automatically through
aria-labelledby. descriptionis associated througharia-describedby. A calleraria-describedbyis kept next to it.- Focus ring via
:focus-visible. - The thumb and track transitions turn off under
prefers-reduced-motion.
Keyboard
| Key | Action |
|---|---|
Space | Toggles the switch |
Tab | Moves focus to / from the switch |