Skip to content

Switch

Form

Toggle switch for on/off boolean states.

On and offDisabled
Open preview

Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.

Usage

Use switches for settings that take effect immediately. Use checked and onCheckedChange together for a controlled switch.

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

Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.

API reference

Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.

Switch props
PropType / DefaultDescription
checkedboolean

Default: —

Controlled on/off state.
onCheckedChange(checked: boolean) => void

Default: —

Handle state changes.
defaultCheckedboolean

Default: —

Initial uncontrolled state.
disabledboolean

Default: false

Prevent interaction.

Build with these too