Switch

On/off toggle. Use for binary settings where the result is immediate (no Save button needed).

Default

Bound with v-model.

Dark previewReplay previewOpen in new tab

Usage

Import the parts you need from the component's folder.

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

With label

Pair with a Label for click targets.

Dark previewReplay previewOpen in new tab

With description

Add a muted description under the label to explain what the toggle controls.

Dark previewReplay previewOpen in new tab

Receive emails about new products.

Sizes

The size prop offers sm and default. For anything larger, scale with a utility class such as scale-125.

Dark previewReplay previewOpen in new tab

Disabled

Disable input.

Dark previewReplay previewOpen in new tab

Invalid

Set data-invalid on the Field and aria-invalid on the Switch, then use FieldError for the message.

Dark previewReplay previewOpen in new tab

Turn this on to receive alerts on your devices.

Choice card

Wrap each Field inside a FieldLabel to turn switches into selectable cards. The active card is highlighted automatically.

Dark previewReplay previewOpen in new tab

API Reference

Switch

PropTypeDefaultDescription
modelValuebooleanfalseChecked state. Supports v-model.
defaultValuebooleanfalseInitial state when v-model is not used.
disabledbooleanfalseDisable input.
idstring—Match with a Label for prop.
EventDescription
update:modelValueFires with the new checked state. Enables v-model.
SlotDescription
thumbOverride the sliding thumb content (e.g. an icon).

Accessibility

Keyboard shortcuts and ARIA behavior.

Shortcut Description
SpaceToggles the switch when focused.
EnterToggles the switch when focused.
TabMoves focus to or from the switch.
  • Uses role=switch with aria-checked reflecting the on/off state.
  • Pair with a label so the control's purpose is announced.