InputSwitch is used to select a boolean value.

import InputSwitch from 'primevue/inputswitch';

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

<InputSwitch v-model="checked" />

Enabling checked property displays the component as active initially.

<InputSwitch v-model="checked" />

Invalid state style is added using the p-invalid class to indicate a failed validation.

<InputSwitch v-model="checked" class="p-invalid" />

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

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

Compatibility with popular Vue form libraries.

VeeValidate is a popular library for handling forms in Vue.

I've read and accept the terms & conditions.

    <div class="card flex justify-content-center">
        <form @submit="onSubmit" class="flex flex-column gap-2">
            <div>I've read and accept the terms & conditions.</div>
            <InputSwitch v-model="value" :class="{ 'p-invalid': errorMessage }" aria-describedby="text-error" />
            <small id="text-error" class="p-error">{{ errorMessage || '&nbsp;' }}</small>
            <Button type="submit" label="Submit" />

Screen Reader

InputSwitch 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>
<InputSwitch inputId="switch1" />

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

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

Keyboard Support

tabMoves focus to the switch.
spaceToggles the checked state.