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

PropTypeDefaultDescription
labelReactNode—Label rendered next to the switch
descriptionReactNode—Helper text under the label. Becomes the accessible description
defaultCheckedbooleanfalseInitial on/off state (uncontrolled)
checkedboolean—Controlled on/off state
onCheckedChange(checked: boolean, event: Event) => void—Called when state changes
disabledbooleanfalseDisable the switch
sxStyleXStyles—StyleX style override

All other props are forwarded to the underlying Base UI Switch.

Accessibility

  • Wraps Base UI Switch — renders with role="switch" and aria-checked.
  • Label is associated automatically through aria-labelledby.
  • description is associated through aria-describedby. A caller aria-describedby is kept next to it.
  • Focus ring via :focus-visible.
  • The thumb and track transitions turn off under prefers-reduced-motion.

Keyboard

KeyAction
SpaceToggles the switch
TabMoves focus to / from the switch