Installation
npx logic2b@next add switchUsage
import { Switch } from "@/components/ui/switch"
<Switch id="airplane-mode" />
Usage notes
Built on Radix Switch.Root; forwards all of its props.
Examples
Controlled
Disabled
Settings list
Accessibility
- Renders a
switchrole element that reflects its on/off state to assistive technology. - Toggle with
SpaceorEnterwhen focused; fully reachable withTab. - Associate a
LabelviahtmlFor(or wrap the control) so the state has an accessible name.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<Switch
defaultChecked
aria-label="Enable notifications"
/>API reference
Generated from the public TypeScript exports in src/ui/switch.tsx.
Switch
ComponentProps: React.ComponentProps<typeof SwitchPrimitive.Root>Accessibility contract
Machine-readable behavior and consumer responsibilities for switch.
- Support
- Primitive-managed
- Pattern
- switch
- Radix Switch
| Keys | Behavior |
|---|---|
| Enter Space | Activate the focused control. |
Built-in semantics
- Exposes role=switch and aria-checked.
Consumer responsibilities
- Associate it with a label that describes the setting, not only the current state.