Switch
Installation
The visible label names the switch; descriptions are linked separately. Explicit aria-label or aria-labelledby naming takes priority. External description IDs are preserved and deduplicated, and conditional descriptions are linked only while rendered.
Usage
Use name and value to include a checked switch in form submission. Both checked and the switched alias remain bindable. A label activates the switch, and supplied ARIA relationships are preserved.
Import Switch and bind its state:
Examples
Basic
With description
Disabled
API reference
Switch
Toggles a boolean value.
| Prop | Type | Default |
|---|---|---|
checked Bindable | boolean | undefined | undefined |
switched Bindable | boolean | undefined | undefined |
label | string | undefined | — |
description | string | undefined | — |
element Bindable | HTMLButtonElement | undefined | — |
onclick | (MouseEventHandler<HTMLButtonElement> & ((e: MouseEvent) => void)) | undefined | — |
pnpm dlx @mielui/svelte add switch