Skip to content

Switch

Turn a setting on or off.

Demos

Size
State
Email notificationsReceive updates when project details change.

Usage

vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'

const items = [
  { value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>

<template>
  <Accordion :items="items" />
</template>

Installation

Complete the shared installation. Copy Switch.vue and index.ts into app/components/ui/switch/.

API

Variants and defaults

PropValuesDefault
sizexs, sm, md, lg, xlsm

Props

PropTypeDefaultDescription
disabledbooleanfalseDisables the switch.
idstringautoHTML id for the button element.
namestring—HTML name for form submission.
requiredbooleanfalseMarks the field as required.
trueValueboolean | string | numbertrueModel value when switched on.
falseValueboolean | string | numberfalseModel value when switched off.
labelstring—Label text. Slot #label takes priority.
descriptionstring—Description text. Slot #description takes priority.
ariaLabelstring—aria-label for icon-only switches with no visible label.
uiSwitchUi—CSS class overrides.

Slots

SlotScoped propsDescription
thumb{ checked }The sliding thumb indicator.
label—Label text. Defaults to the label prop.
description—Description text. Defaults to the description prop.

Events

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

Keyboard

KeyBehavior
Enter / SpaceToggles focused switch.
Tab / Shift + TabUses native document focus order.

Visible label is associated with switch, so mouse and touch activation on label also toggles it.