Switch
Turns a setting on or off, and the change applies at once. Screen readers announce it as a switch, on or off.
Showcase
<LnxSwitch v-model="..." <-- Pass a reactive variable here to bind its value @update:modelValue="..." <-- Two way binding of the component > Email notifications </LnxSwitch>
labelPosition
SwitchLabelPositionThe label before the switch, with the switch at the end of the row as in settings, or after it Default value: SWITCH_LABEL_POSITIONS.ENDWhen to use
- For a setting that applies as soon as it changes, like turning notifications on.
- For a choice that only applies when a form is submitted, or to accept terms, use a Checkbox.
Examples
Settings row
With label-position="start" the label goes first and the switch at the end of the row.
When someone comments on an issue you follow.
vue
<LnxSwitch v-model="notifications" label-position="start">
Email notifications
<template #helper>
When someone comments on an issue you follow.
</template>
</LnxSwitch>1
2
3
4
5
6
2
3
4
5
6
Saving
While the change is saved, is-loading disables the switch and shows a spinner in the thumb.
vue
<LnxSwitch :model-value="digest" :is-loading="isSaving" @update:model-value="save">
Weekly digest
</LnxSwitch>1
2
3
2
3
API
Props
| Prop | Type | Description |
|---|---|---|
v-model | boolean | Whether the switch is on Default: false |
is-loading | boolean | When loading, it is disabled and the thumb shows a spinner Default: false |
label-position | SwitchLabelPosition | The label before the switch, with the switch at the end of the row as in settings, or after it Default: SWITCH_LABEL_POSITIONS.END |
disabled | boolean | Native attribute: it can't be switched Default: false |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | boolean | Two way binding of the component |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | The label of the switch |
helper | — | The helper message of the switch |
Types
SwitchLabelPosition
ts
export const SWITCH_LABEL_POSITIONS = {
START: 'start',
END: 'end',
} as const;
export type SwitchLabelPosition = ValueOf<typeof SWITCH_LABEL_POSITIONS>;1
2
3
4
5
2
3
4
5