Search documentation

Search the documentation and open a page.

A control that allows the user to toggle between checked and unchecked states.

Loading...

Installation

pnpm dlx shadcn@latest add @wirekyt/switch

Composition

Switch ├── SwitchLabel (optional) ├── SwitchControl │ └── SwitchThumb └── SwitchHiddenInput

Examples

Card Controls

Loading...

Choice Cards

Loading...

Default

Loading...

Invalid

Loading...

Password Protection

Loading...

Share Project

Loading...

Sizes

Loading...

With Description

Loading...

API Reference

Switch

PropTypeDefaultDescription
idstring | undefined—Unique identifier used to connect the component parts.
idsElementIds | undefined—Overrides generated identifiers for individual parts.
labelstring | undefined—Configures label.
disabledboolean | undefinedfalseDisables interaction with the component.
invalidboolean | undefined—Marks the associated form control as invalid.
requiredboolean | undefinedfalseMarks the associated form control as required.
readOnlyboolean | undefinedfalsePrevents changes while preserving focus and navigation.
onCheckedChange((details: CheckedChangeDetails) => void) | undefined—Runs when checked changes.
checkedboolean | undefined—Checked state when the component is controlled.
defaultCheckedboolean | undefined—Initial checked state when the component is uncontrolled.
namestring | undefined—Name used when submitting the value with a form.
formstring | undefined—Associates the control with a form by ID.
valuestring | number | undefined—Current value when the component is controlled.

Context, Hooks, and Types

ExportAPI
SwitchContextRender-prop component that exposes component state and actions.
SwitchRootProviderProvides an externally created API to the component tree.
useSwitchCreates or accesses the component API.
useSwitchContextReturns the nearest component API.
SwitchCheckedChangeDetailsType for the details object passed to the matching change callback.