Skip to content
GitHub (opens in a new tab)

Switch

Immediate on/off setting.

stableAtomcontracts/switch.json

Preview

Switch

Immediate on/off. Pill track, role=switch. Not a Checkbox.

Master

Toggle the medium switch on the canvas. Variants shows sizes and disabled.

Usage

Instant settings only. Checkbox for multi-select or agree-to-terms. RadioGroup for one of several. Unlabeled needs ariaLabel.

Do's

  • Settings rows (notifications, dark mode)
  • Binary preference that takes effect now

Don'ts

  • Multi-select or agree-to-terms — use Checkbox
  • Choosing one of several options — use RadioGroup
  • Primary form submit actions — use Button
<Switch
  label="Notifications"
  size="md"
  checked={true}
  onChange={() => {}}
/>

Immediate on/off setting. Pill track, role=switch. Not a Checkbox.

When to use

  • Settings rows (notifications, dark mode)
  • Binary preference that takes effect now

When not to use

  • Multi-select or agree-to-terms — use Checkbox
  • Choosing one of several options — use RadioGroup
  • Primary form submit actions — use Button

What an agent reads

import { Switch } from "agentic-ds-kit";
must
  • role=switch
  • aria-checked reflects on/off
  • Keyboard uses button defaults (Space/Enter)
  • focus-visible kit ring
  • Disabled state is exposed
  • Visible label via label/htmlFor OR ariaLabel when unlabeled
defaults
  • size md
  • disabled false
  • defaultChecked false
stops if
  • Do not invent local Switch, Toggle, or ToggleGroup
  • Do not use Checkbox for instant settings
  • Do not use raw hex
  • Do not ship unlabeled without ariaLabel
  • Do not export Thumb or SwitchGroup

From contracts/switch.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
idstringNo—useId fallback
labelstringNo—visible text; required unless ariaLabel is set
ariaLabelstringNo—required when label is omitted
sizesm | md | lgNomd—
disabledbooleanNofalse—
checkedbooleanNo—controlled
defaultCheckedbooleanNofalseuncontrolled
onChangefunctionNo—(checked: boolean) => void
describedBystringNo—Field wires hint and error ids onto the switch
  • Component
    →

    Checkbox

    Multi-select or confirmation control.

  • Component
    →

    RadioGroup

    Choose exactly one option from a small visible set.

  • Component
    →

    Button

    Clickable action control with appearance × mode (plus an optional flat set) and a fixed set of sizes.