ToggleSwitch

ToggleSwitch is used to select a boolean value.

import { ToggleSwitchModule } from 'primeng/toggleswitch';

Two-way value binding is defined using ngModel.

Enabling ngModel property displays the component as active initially.

The handle template is available to display custom content.

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

The invalid state is applied using the ⁠invalid property to indicate failed validation, which can be integrated with Angular Forms.

ToggleSwitch can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.

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 inputId prop or using ariaLabelledBy, ariaLabel props.

<label for="switch1">Remember Me</label>
<p-toggleswitch inputId="switch1" />

<span id="switch2">Remember Me</span>
<p-toggleswitch ariaLabelledBy="switch2" />

<p-toggleswitch ariaLabel="Remember Me" />

Keyboard Support

KeyFunction
tabMoves focus to the switch.
spaceToggles the checked state.
Templates
Highly customizable application templates to get started in no time with style. Designed and implemented by PrimeTek.