Skip to content

Switch for Angular

AngularForm Inputs

An on/off setting that takes effect immediately, built on a native <input type=“checkbox” role=“switch”> with a track and thumb. Switches have no required state; validity is valid unless a custom error is set (for example when saving the setting failed).

  • Immediate settingsAn on/off control for settings that take effect right away.
  • Native underneathA native checkbox with the switch role keeps keyboard and form behavior.
  • Save failuresShow a custom error when saving the setting fails.
  • Form readySubmits its value with the form like a checkbox.

Behavior, design tokens, and limitations are described on the Switch page; this page covers the Angular API.

import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { AuiSwitch } from '@absoluteui/angular/switch';
@Component({
selector: 'app-settings',
imports: [ReactiveFormsModule, AuiSwitch],
template: `<aui-switch label="Email notifications" description="Weekly summary" [formControl]="notifications"></aui-switch>`,
})
export class SettingsComponent {
readonly notifications = new FormControl(false, { nonNullable: true });
}
Terminal window
npm install @absoluteui/angular @absoluteui/components @absoluteui/core @absoluteui/theme

Setup with provideAbsoluteUI() is covered in Getting started. Styles are included with the component.

import { AuiSwitch } from '@absoluteui/angular/switch';

Defaults for every instance: provideAbsoluteUIConfig({ components: { switch: { ... } } }) (see Configuration).

Class AuiSwitch; template reference #ref="auiSwitch".

Server rendering: Renders on the server; the browser re-creates it after hydration.

Angular forms: implements ControlValueAccessor and Validator; the form value is boolean. Bind [formControl], formControlName, or [(ngModel)]; validation messages of the component report through the aui error key. See Forms.

Input Type Default Description
label string Required. Visible label and accessible name; clicking it toggles the switch.
hideLabel boolean false Visually hide the label; it remains the accessible name.
value string 'on' Submitted value when on.
name string Form field name.
description string Help text referenced by aria-describedby.
disabled boolean false Disables the switch.
icons Partial<SwitchIcons> Icon slot overrides.
validationTiming ValidationTiming 'blur' When a custom error message first appears; afterwards it updates live.
locale string 'en-US' Message locale.
Model Type Change output Description
[(checked)] boolean (checkedChange) The checked: [(checked)] without forms; with Angular forms, bind the form control instead.
Output Payload Description
(changed) SwitchChangeDetail The user toggled the switch. Re-emits aui-change.

Call them through a viewChild query or a template reference.

Method Description
reportValidity(): boolean | undefined Show a custom error now and return validity.
setCustomError(message: string | null): void External error, for example a failed save; cleared when the user toggles.
getFormValue(): string | null | undefined value when on, otherwise null.
focus(): void Focus the switch.
reset(): void Restore the initial state and clear dirty/touched/submitted state.

AuiSwitchHarness from @absoluteui/angular/testing. <aui-switch>.

Pattern: Native <input type=“checkbox” role=“switch”> with a <label for> association (WAI-ARIA APG Switch).

The Angular component renders the framework-neutral component, so its keyboard support, roles, WCAG 2.2 criteria, budgets, and import cost apply unchanged: see Switch: Accessibility and performance.