Components

Switch

A toggle control for binary or custom on/off values.

An accessible on/off toggle. Renders as a role="switch" button and supports custom v-model values, labels, descriptions, and fully custom track/thumb rendering via slots.

Anatomy

  • #thumb — the sliding indicator inside the track
  • #label — the label beside the switch
  • #description — supplementary text below the label

Usage

Email notificationsReceive updates about your account.Dark modeApply a dark theme to the interface.Sound effectsPlay sounds for actions and alerts.

Examples

Custom thumb

<template>
  <Switch v-model="enabled" class="my-switch">
    <template #thumb="{ checked }">
      <span :class="['thumb', { 'thumb--on': checked }]" />
    </template>
  </Switch>
</template>

With description

<template>
  <Switch
    v-model="enabled"
    label="Dark mode"
    description="Applies a dark theme across the interface."
  />
</template>

Custom true/false values

<script setup lang="ts">
const theme = ref<"dark" | "light">("light");
</script>

<template>
  <Switch
    v-model="theme"
    true-value="dark"
    false-value="light"
    label="Dark mode"
  />
</template>

Icon-only switch

Use aria-label when there's no visible label text.

<template>
  <Switch v-model="muted" aria-label="Mute audio" class="my-switch" />
</template>

API Reference

Props

PropTypeDefaultDescription
disabledbooleanfalseDisables the switch.
idstringautoHTML id for the button element.
namestringHTML name for form submission.
requiredbooleanfalseMarks the field as required.
trueValueboolean | string | numbertrueModel value when switched on.
falseValueboolean | string | numberfalseModel value when switched off.
labelstringLabel text. Slot #label takes priority.
descriptionstringDescription text. Slot #description takes priority.
ariaLabelstringaria-label for icon-only switches with no visible label.
uiSwitchUiCSS class overrides.

Slots

SlotScoped propsDescription
thumb{ checked }The sliding thumb indicator.
labelLabel text. Defaults to the label prop.
descriptionDescription text. Defaults to the description prop.

Emits

EventPayloadDescription
value-change[value: SwitchValue, details]Fired when the switch state changes.

UI Options

KeyDescription
wrapperThe outer wrapper element.
rootThe interactive button (the switch track).
thumbThe thumb indicator element.
labelThe label element.
descriptionThe description element.