ComponentsSelection
Switch
Shared primitiveEnable or disable an immediate setting.
@/components/ui/switch
Composition preview
Try Switch alongside its related selection components. These examples keep all actions local.
Usage
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
<>
<div className="flex items-center gap-2">
<Switch id="notifications" checked={enabled} onCheckedChange={setEnabled} />
<Label htmlFor="notifications">Notifications</Label>
</div>
</>Composition recipe. Supply application state, handlers and persistence in the owning product component. Inspect the installed source before extending its API.
API & composition
checked/defaultChecked, onCheckedChange, disabled; size: sm or default
Usage & accessibility
Use a stable setting label. NativeSwitch preserves existing checkbox-input event and form contracts.
Implementation contract
src/components/ui/switch.tsx
Use named variants and semantic theme tokens. Preserve existing input values, refs, focus and cancellation behavior. Verify keyboard, narrow layouts and pending/error states when behavior changes.