Switch
A control that allows the user to toggle between checked and not checked.
Preview
Installation
npx sigma-ui@latest add switchUsage
<script setup lang="ts">
import { ref } from 'vue';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
const airplaneMode = ref(false);
</script>
<template>
<div class="flex items-center gap-2">
<Switch
id="airplane-mode"
v-model="airplaneMode"
/>
<Label for="airplane-mode">Airplane Mode</Label>
</div>
</template>v-modelis aboolean. UsedefaultValueinstead for an uncontrolled switch.- Give the switch an
idand point aLabelat it withfor, so the label is announced and clicking it toggles the switch.
Examples
Form
API Reference
Switch
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe state of the switch when it is initially rendered. Use when you do not need to control its state. | boolean | - |
modelValueThe controlled state of the switch. Can be bind as | boolean | null | - |
disabledWhen | boolean | - |
id | string | - |
valueThe value given as data when submitted with a | string | - |
trueValueThe value used when the switch is on. Defaults to | boolean | - |
falseValueThe value used when the switch is off. Defaults to | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value of the switch changes. | [payload: boolean] |
Accessibility
Adheres to the Switch WAI-ARIA design pattern. Reka UI renders it as a button with role="switch" and aria-checked.
| Key | Description |
|---|---|
| Tab | Moves focus to the switch. |
| Space | Toggles the switch. |
| Enter | Toggles the switch. |