Skip to content
Status
Stable
Accessibility
Reviewed
Package
tenet-ui@0.5.0
Import
import { Switch } from 'tenet-ui';

Also accepts every prop of Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>.

When to use: an immediate on/off setting that takes effect right away (e.g. “Enable notifications”). For a choice the user confirms later with a Save/Submit button, prefer Checkbox.

  • Give it a label via the label prop (or an associated aria-label). A switch with no name is unusable on a screen reader.
  • It is a real <input type="checkbox" role="switch"> — control it with checked + onChange, or leave it uncontrolled with defaultChecked.
  • Use caption for a one-line explanation; don’t pile a paragraph next to a toggle.
  • Use size="small" only in dense rows (e.g. a settings table). Default to medium.
  • Never build a toggle out of a <div> with an onClick — you lose the role, the checked state, and keyboard support.
  • ✅ <Switch label="Enable notifications" defaultChecked />
  • ✅ controlled: <Switch label="Dark mode" checked={dark} onChange={e => setDark(e.target.checked)} />
  • ❌ <Switch> with no label and no aria-label.
  • ❌ Using a Switch for a form value you submit on save — that’s a Checkbox.
5 stories for Switch, open in Storybook

The full matrix (all args, controls, accessibility panel) is in Storybook.

PropTypeDefaultDescription
labelReactNodeNoneVisible label rendered next to the switch.
captionReactNodeNoneOptional helper text under the label.
size'small' | 'medium'
SwitchSize
mediumControl track / knob scale.
invalidbooleanfalseMark the field as invalid (sets aria-invalid and a danger border).