Switch
A setting that takes effect immediately. It is announced with role="switch", so a screen reader says on or off rather than ticked, and that is the whole reason it is not a checkbox.
Usage
Examples
Hint
label writes the text beside the switch, and the default slot replaces it. hint adds a caption underneath, tied to the switch through aria-describedby, which is where a setting says what turning it on does.
Label position
labelPosition moves the label before the switch instead of after it.
Spread
spread takes the full width offered and pushes the label and the switch to opposite ends of the row.
Read-only
readonly shows the setting without letting it change: a click or the Space key is cancelled. The switch stays focusable, is submitted with its form and is announced as read-only. It says so on screen either way round, an on switch trading the accent for the muted colour and an off one sinking behind a hairline ring.
Disabled
disabled prevents the switch from being flicked and greys it out through the colour tokens, on as well as off. The keyboard steps over it.
API
Props
| Prop | Type | Default |
|---|---|---|
label | string | none |
| The text beside the switch, which names it. The default slot replaces it. | ||
hint | string | none |
| A line of help under the label. It is tied to the switch for assistive technology, so it is read out after the label rather than as part of it. | ||
labelPosition | SwitchLabelPosition'start' | 'end' | 'end' |
| Which side of the switch the label sits on. | ||
spread | boolean | false |
| Pushes the label and the switch to opposite ends of the line, so a column of settings lines its switches up down one edge. | ||
invalid | boolean | false |
| Marks the field as invalid, which rings the track and tells assistive technology so. Use it for a rule the browser cannot check by itself; native validity is already handled without it. | ||
disabled | boolean | false |
| Makes the switch unusable. It greys out through the colour tokens rather than through opacity, so it stays legible on any surface. | ||
readonly | boolean | false |
| Shows the setting without allowing it to be changed. The switch can still be focused, is announced as read-only and is still submitted with its form; a click or the Space key simply changes nothing. | ||
v-model | boolean | false |
Whether the switch is on. It is bound to a real hidden <input type="checkbox">, so the value submits with the form like any other field. | ||
Slots
| Slot | Type |
|---|---|
default | {} |
The label, when it needs more than the label prop's text, a link or a piece of emphasis. It sits inside the <label>, so clicking the words toggles the switch. | |
CSS variables
| Token | Value |
|---|---|
--vectis-control-size-switch-w | 2.5rem |
--vectis-control-size-switch-h | 1.25rem |
--vectis-control-size-switch-pad | 0.125rem |