v0.5.1

Switch

Toggle switch for on/off binary settings, built on Radix UI.

Installation

npx paubha@latest add switch

Usage

import { Switch } from "@/components/ui/switch";

<Switch label="Email notifications" />

Examples

States

API reference

PropTypeDefaultDescription
labelReactNode—Clickable label, linked to the control via for/id.
checkedboolean—Controlled checked state.
defaultCheckedboolean—Uncontrolled initial checked state.
onCheckedChange(checked: boolean) => void—Called when the switch is toggled.
disabledboolean—Prevents toggling.

Accessibility

Accessibility

  • Role. role="switch" with aria-checked true/false, provided by Radix.

  • Keyboard. Space toggles.

  • Label. Clicking the label toggles the switch.

  • Focus. Visible glow-focus ring on the track.