Switch
Toggle component with a thumb element. Accessible — renders as a <button role="switch"> with aria-checked.
Preview
Preview
Anatomy
import { Switch } from '@wire-ui/react'
<Switch.Root checked={on} onCheckedChange={setOn}>
<Switch.Thumb />
</Switch.Root>Root props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Controlled checked state |
defaultChecked | boolean | false | Initial state for uncontrolled use |
onCheckedChange | (checked: boolean) => void | — | Called when toggled |
disabled | boolean | false | Disables the switch |
Data attributes
| Attribute | Element | Values |
|---|---|---|
data-state | Root, Thumb | "checked" / "unchecked" |
data-disabled | Root | Present when disabled |
Accessibility
role="switch"witharia-checkedreflects the current state- Keyboard: Space toggles the switch
Last updated on