Form
ToggleSwitch
An on/off switch over a native checkbox, with a header above and on/off content beside it.
WAI-ARIA tested
Import
main.ts
import { ToggleSwitch } from '@vitral/vue';Header and state
With `show-state-label`, the locale's On/Off is shown beside the switch.
Custom content
Content shown beside the switch for each state. The second switch has no header, so it is named with aria-label.
States
API
Read from packages/vue/src/components/ToggleSwitch/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| label | string | The header above the switch (the header, not the on/off text); it is the switch's `<label>` and so its accessible name. |
| onLabel | string | Shown beside the switch while it is on. |
| offLabel | string | Shown beside the switch while it is off. |
| showStateLabel | boolean | Show the locale's On/Off beside the switch when no `onLabel`/`offLabel` is given. |
| invalid | boolean | — |
| disabled | boolean | — |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| change | event: ToggleSwitchChangeEvent | — |
| focus | event: FocusEvent | — |
| blur | event: FocusEvent | — |
Slots
| Name | Slot props | Description |
|---|---|---|
| default | — | Replaces the header text. |
| content | (props: { checked: boolean }) | Replaces the on/off content beside the switch. |