Toggle
A two-state button that can be either on or off.
Preview
Installation
npx sigma-ui@latest add toggleUsage
<script setup lang="ts">
import { Toggle } from '@/components/ui/toggle';
</script>
<template>
<Toggle aria-label="Toggle bold">
Bold
</Toggle>
</template>- Use
v-modelto control the pressed state, ordefaultValuefor an uncontrolled toggle. variantisdefaultoroutline, andsizeisdefault,sm, orlg.
Examples
Default
Outline
With Text
Small
Large
Disabled
API Reference
Toggle
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe pressed state of the toggle when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
modelValueThe controlled pressed state of the toggle. Can be bind as | boolean | null | - |
disabledWhen | boolean | false |
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 | - |
variantVisual style of the toggle. | "default" | "outline" | null | "default" |
sizeHeight and horizontal padding of the toggle. | "default" | "sm" | "lg" | null | "default" |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value of the toggle changes. | [value: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Follows the toggle button variant of the Button WAI-ARIA design pattern. Reka UI renders a button with aria-pressed. Set aria-label when the toggle only contains an icon.
| Key | Description |
|---|---|
| Tab | Moves focus to the toggle. |
| Space | Toggles the pressed state. |
| Enter | Toggles the pressed state. |