WlSwitch
Appearance
Full example
<div class="wl-stack" data-space="md">
<WlSwitch v-model="value" aria-label="Email notifications" >
{{ "Email notifications" }}
</WlSwitch>
</div>States
Full example
<div class="wl-stack" data-space="md">
<WlSwitch v-model="value" aria-label="Email notifications" >
{{ "Email notifications" }}
</WlSwitch>
</div>Settings and states
Compare sm/md, labels, a validated setting with an error, disabled and resetting models.
Two sizes and a slot label
Space toggles the focused switch. The label names the setting; aria-checked conveys its state.
Error and unavailable setting
Notifications: enabled. Brief: disabled. Protection: disabled.
Full example
<script setup lang="ts">
import { WlButton, WlField, WlSwitch } from "legato-ui";
import { ref } from "vue";
const notifications = ref(true);
const compactNotifications = ref(false);
const protectedMode = ref(false);
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlSwitch">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Two sizes and a slot label" }}</h3>
<WlSwitch v-model="notifications" size="md">{{ "Notifications, md" }}</WlSwitch>
<WlSwitch v-model="compactNotifications" size="sm">{{ "Brief notifications, sm" }}</WlSwitch>
<p class="wl-text-small wl-text-muted">{{ "Space toggles the focused switch. The label names the setting; aria-checked conveys its state." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Error and unavailable setting" }}</h3>
<WlField
id="docs-switch-protected"
v-slot="{ id, ariaDescribedby, invalid }"
:error="protectedMode ? undefined : 'Enable protection before continuing.'"
><WlSwitch
:id="id"
v-model="protectedMode"
:invalid="invalid"
:aria-describedby="ariaDescribedby"
>{{ "Protected mode" }}</WlSwitch></WlField>
<WlSwitch :model-value="true" disabled>{{ "Archiving is enabled by an administrator" }}</WlSwitch>
<div class="wl-inline" data-space="sm">
<WlButton size="sm" @click="notifications = true; compactNotifications = false; protectedMode = false">
{{ "Reset settings" }}
</WlButton>
</div>
<p class="wl-text-small" role="status">{{
"Notifications:"
}} {{
notifications ? "enabled" : "disabled"
}}{{
". Brief:"
}} {{
compactNotifications ? "enabled" : "disabled"
}}{{
". Protection:"
}} {{
protectedMode ? "enabled" : "disabled"
}}.</p>
</section>
</div>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: booleanWhether enabled (default false).
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
size | WlSwitchSize | "md" | Size. |
disabled | boolean | false | Disables the switch. |
invalid | boolean | false | Error state. |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
loading | boolean | false | Indicate pending work supplied by the application. |
labelPosition | "start" | | "end" | Place the visible label before or after the switch. |
density | WlDensity | "default" | Spacing density for this component family. |
Events
| Event | Payload | When emitted |
|---|---|---|
update:modelValue | boolean | Emitted when the component requests a model change; the payload is the next value. |
Slots
| Slot | Type / values | Content |
|---|---|---|
default | — | Label next to the switch. |
Pass-through: pt
Sections WlSwitch are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
input | input.wl-check-input | The input section in WlConfig.pt.switch configuration. |
slider | span.wl-switch__slider | The slider section in WlConfig.pt.switch configuration. |
handle | span.wl-switch__handle | The handle section in WlConfig.pt.switch configuration. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- The native checkbox has role=switch. The default slot label names the setting; aria-checked announces its boolean state.
- Space toggles the focused switch. Keep the same label in its on and off states.
- Supported sizes are sm/md. disabled prevents changing the setting; invalid needs explanatory text from the application.
- Associate the error through aria-describedby; the application saves the setting and performs related actions.
Keyboard and application responsibilities
| Key | Action |
|---|---|
| Tab / Shift+Tab | Focus an enabled native control. |
| Space | Change the current choice. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.