Switch
Turn a setting on or off.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/switchComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/form @siteplane/input @siteplane/labelField is installed with Input.
Usage
import { Label } from "@/siteplane/components/label";
import { Switch } from "@/siteplane/components/switch";
<Label>
<Switch />
Marketing emails
</Label>;With description
Place a FieldLabel and a FieldDescription before the switch, inside a Field. The Field connects both to the switch, which sits at the end of the row, centered on it.
Save changes to documents as you type.
Disabled and invalid
disabled blocks interaction and leaves the value out of form data. aria-invalid only applies the invalid style; it does not validate.
Card style
Wrap the text and the switch in Label variant="card" so the whole card toggles the setting. Label owns the shared hover, checked and disabled styles.
Controlled state
Pass checked with onCheckedChange when your application owns the value; otherwise use defaultChecked.
Form integration
Inside a Field, the switch uses the field’s name and submits its value (on when none is set) only while it is on, unless you set uncheckedValue.
Sizes
Omit size to inherit the provider’s control size.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
size | sm | md | lg | xl | provider / lg | Control dimensions. |
children | ReactNode | unset | Rendered only for menu-item; the control supplies its own thumb. |
checked / default | boolean | unset / false | Controlled state or initial state. |
on | (checked, eventDetails) => void | unset | Called when the user changes the checked state. |
disabled | boolean | false | Prevents interaction. |
name / value | string | unset | Native form participation. An on switch submits value (on if value is unset). |
unchecked | string | unset | Value submitted while the switch is off. |
SwitchProps describes the size extension; SwitchPrimitive is the Base UI namespace. Other props, including required, readOnly, render and inputRef, follow Base UI Switch. Styled className is a string.
switchVariants({ size, className }) returns the classes of the switch track that menu rows draw, with lg size; switchThumbClassName and switchMenuTrackClassName export the matching thumb and track composition strings. The standalone control takes its look from the kit stylesheet, and so does the edge of every track: a menu row's track carries data-slot="switch-track" and gets the standalone control's 3:1 edge. They do not create switch behavior.
Usage notes
Space changes the focused control. Supply a visible associated Label or an accessible name. Use Checkbox Group for multiple related choices and Radio Group for exactly one choice. Switch has no indeterminate state.
The thumb rests at the inline start of the track and travels toward its end when the switch turns on, so in a right-to-left page it starts on the right and moves left, within the track. The same holds for the switch rows of menus.