Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Switch

A binary control that allows users to toggle an option on or off. Built on the @zag-js/switch machine, which manages the WAI-ARIA role, hidden input, and keyboard interactions across React, Svelte, and Solid.

React Switchlive
import { Switch } from "@/components/ui/switch";
<Switch label="Enable notifications" defaultChecked />
Terminal window
npx @glaceon/cli add switch --framework react # or svelte, solid
Element Data Attribute Value Description
control data-state "checked" | "unchecked" Applied based on the current state.
control data-disabled "" Present when the switch is disabled.
thumb data-state "checked" | "unchecked" Matches the parent control state.
Prop Type Default Description
label string "Switch" Visible label text linked to the control.
defaultChecked boolean false Uncontrolled initial checked state.
disabled boolean false Prevents user interaction when true.
name string undefined Form field name for the hidden input.
value string undefined Form field value for the hidden input.
Key Description
Space / Enter Toggles the switch state when focused.