Component
Vue Toggle Switch Component
<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.
Properties
Control props
Switch size. Matches DomButton size names.
Field props
Optional ID override. By default parent forms derive the input ID from the field path using underscores.
Local field name. Parent forms derive the full field path and native HTML name from the form hierarchy.
Visible field label.
Optional helper copy below the field.
Placeholder shown when the control is empty.
Validation errors for this field.
Validators
No validators yet.
Validators attached to this field. Use functions in Vue code, or serializable records such as { name: "minLength", props: { min: 2 } } in generated schemas.
Render default field chrome, or hide chrome while keeping form state wiring.
npm install @getdom/studio<script setup>
import '@getdom/studio/style.css';
import { reactive } from 'vue';
import { DomToggle } from '@getdom/studio';
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",
"size": "md"
});
</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" size="md" />
</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. |
| size | 'sm' | 'md' | 'lg' | 'md' | Switch size. Uses the same size names as DomButton. |
| disabled | boolean | false | Disable interaction. |
Keyboard
- Space / EnterToggle the value.
- TabMove focus through toggles in source order.