Toggle
A two-state button that can be either on or off.
Features
- Full keyboard navigation.
- Can be controlled or uncontrolled.
Installation
Install the component from your command line.
sh
$ npm add reka-uiAnatomy
Import the component.
vue
<script setup>
import { Toggle } from 'reka-ui'
</script>
<template>
<Toggle />
</template>API Reference
Root
The toggle.
| Data Attribute | Value |
|---|---|
[data-state] | "checked" | "unchecked" |
[data-disabled] | Present when disabled |
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Space | Activates/deactivates the toggle. |
Enter | Activates/deactivates the toggle. |
Headless composable
useTogglePressed returns pressed, toggle(), setPressed(), lastChangeDetails and the root part surface (aria-pressed, data-state, the press handler). It takes modelValue, defaultValue, disabled, onBeforeUpdate and onUpdate. It is pure, so it can be called outside setup(). The composable is experimental; see Headless composables.
