ToggleSwitch is used to select a boolean value.

import ToggleSwitch from 'primevue/toggleswitch';

Two-way value binding is defined using v-model.

<ToggleSwitch v-model="checked" />

Enabling checked property displays the component as active initially.

<ToggleSwitch v-model="checked" />

Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.

<ToggleSwitch v-model="checked" :invalid="!checked" />

When disabled is present, the element cannot be edited and focused.

<ToggleSwitch v-model="checked" disabled />

Screen Reader

ToggleSwitch component uses a hidden native checkbox element with switch role internally that is only visible to screen readers. Value to describe the component can either be provided via label tag combined with id prop or using aria-labelledby, aria-label props.

<label for="switch1">Remember Me</label>
<ToggleSwitch inputId="switch1" />

<span id="switch2">Remember Me</span>
<ToggleSwitch aria-labelledby="switch2" />

<ToggleSwitch aria-label="Remember Me" />

Keyboard Support

tabMoves focus to the switch.
spaceToggles the checked state.