Switch
Applies role=switch to a native checkbox input to preserve form and browser behavior. Supports checked, defaultChecked, and onCheckedChange.
@neumorphism-ui/switchPreview
Installation
Installation: switch
npx shadcn@latest add @neumorphism-ui/switchThe CLI resolves npm dependencies, base tokens, utilities, and component source in order.
New to this Registry? Set up the namespace before continuing.
Usage
Usage: Installation
npx shadcn@latest add @neumorphism-ui/switch @neumorphism-ui/labelImport
Switch import code
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"Example
Switch usage code
<div className="flex items-center justify-between gap-4"> <Label htmlFor="system-theme">Use system theme</Label> <Switch id="system-theme" name="systemTheme" defaultChecked /> </div>
API Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Switch | checked / defaultChecked | boolean | — | The controlled on state or initial uncontrolled state. |
Switch | onCheckedChange | (checked: boolean) => void | — | Called when the on state changes. |
Switch | onChange | React.ChangeEventHandler<HTMLInputElement> | — | Receives the native checkbox change event. |
Switch | disabled | boolean | false | Disables input and pointer interaction. |
Switch | name / value / required | native input props | — | Native checkbox attributes used for form submission. |
Accessibility
- 01
Applying role=switch to a real checkbox communicates the checked state to assistive technology and preserves Space key interaction.
- 02
Connect Label htmlFor to the Switch id, or provide an aria-label.
- 03
Checkbox may be more appropriate for a boolean choice that is not applied immediately and requires a separate save action.