Component
Toggle
<dom-toggle>Accessible switch with role=switch, keyboard support, and a smooth thumb animation.
Playground
Try every prop live
Toggle playground
Edit props in the inspector — the live switch and synthesised source stay in sync.
Playground.vuevue
<script setup>
import { reactive } from 'vue';
import { DomToggle } from '@getdom/studio/vue';
const data = reactive({
"modelValue": true,
"id": "",
"name": "",
"label": "Notifications",
"description": "",
"placeholder": "",
"required": false,
"disabled": false,
"readOnly": false,
"invalid": false,
"errors": {},
"visible": true,
"validators": [],
"validateOnBlur": true,
"chrome": "field"
});
</script>
<template>
<DomToggle
v-bind="data"
@update:modelValue="data.modelValue = $event"
/>
</template>Demo
Live preview
Usage
Vue
<script setup>
import { DomToggle } from '@getdom/studio/vue';
import { ref } from 'vue';
const on = ref(true);
</script>
<template>
<DomToggle v-model="on" label="Notifications" />
</template>Usage
Web component
<dom-toggle checked aria-label="Notifications"></dom-toggle>
<script type="module">
import '@getdom/studio/headless';
document.querySelector('dom-toggle')
.addEventListener('dom:change', (e) => console.log(e.detail.checked));
</script>Props
Props
| Name | Type | Default | Description |
|---|---|---|---|
| v-model | boolean | false | Checked state. |
| label | string | — | Visible label next to the toggle. |
| disabled | boolean | false | Disable interaction. |
Keyboard
- Space / EnterToggle the value.
- TabMove focus through toggles in source order.