For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/switch.md.

Switch

An on/off switch for settings. Tap it or drag its thumb across, and give it variant="glass" for each platform's own switch.

Installation

npx @blotch/dolan add switch
import { UiSwitch } from '../components/ui/switch';
Tip

This also adds Glass, which draws the glass variant's lens, and Icon, whose copy of the theme colors gives the iOS colors their dark mode.

Usage

src/app/app.ts
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiLabel } from '../components/ui/label';
import { UiSwitch } from '../components/ui/switch';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, UiLabel, UiSwitch],
  template: `
    <view class="flex flex-row items-center justify-between">
      <ui-label>Bluetooth</ui-label>
      <ui-switch [(checked)]="bluetooth" accessibility-label="Bluetooth" />
    </view>
  `,
})
export class App {
  protected readonly bluetooth = signal(false);
}
  • This example also uses Label.
  • A tap toggles it, and so does dragging the thumb across. It lands on the side you let go nearer, as on iOS.
  • It taps the phone lightly as it flips, with LynxHaptics. Setting checked from code doesn't.
  • A drag starts only once your finger moves sideways, so a scroll that starts on the switch scrolls the page. A sideways drag doesn't scroll it.
  • The default switch is 44 by 24 pixels: the primary color when on, the input color when off.

Glass

Each platform's own switch:

<ui-switch variant="glass" [(checked)]="wifi" accessibility-label="Wi-Fi" />

On iOS 26 the thumb turns into a Liquid Glass lens while you touch it, bigger than the track, and turns solid again when you let go. It's the one place glass sits on content: Apple keeps glass for the layer above content, except on sliders and switches, and only while they're touched.

What each platform draws:

PlatformSwitch
iOS 26 and lateriOS 26's 63 × 28pt switch, whose thumb turns to glass while touched
iOS 15 to 25The classic 51 × 31pt switch, whose thumb stretches while touched
AndroidA Material 3 switch: 52 × 32dp, outlined when off, its handle grows while pressed
Android, with provideGlass()iOS 26's switch, with Android's glass
Web previewiOS 26's switch, with the glass drawn by WebGL
  • iOS draws it green when on, as UIKit does whatever your app's tint color. Its colors follow your app's color scheme, which provideIconTheme() sets.
  • Material uses the theme's colors: primary when on, secondary with a muted-foreground outline when off.

Tint

tint colors the track while the switch is on, in every look, as UIKit's onTintColor does: a color written out, or a theme variable. Without it, each look keeps its own: the system green on iOS, the theme's primary color elsewhere. Material's pressed state layer takes it too.

<ui-switch
  variant="glass"
  tint="var(--brand)"
  [(checked)]="wifi"
  accessibility-label="Wi-Fi"
/>

Disabled

<view class="flex flex-row gap-3">
  <ui-switch disabled />
  <ui-switch disabled [checked]="true" />
</view>

A disabled switch dims and ignores taps and drags.

Listen without a signal

<ui-switch (changed)="onNotifications($event)" />

changed emits the new state after each tap or drag that changes it.

Forms

checked is a model(), so the switch works with every Angular forms API:

<ui-switch [formControl]="wifi" />
<ui-switch [(ngModel)]="wifi" />
<ui-switch [formField]="settings.wifi" />

UiSwitch implements Signal Forms' FormCheckboxControl. Each tap or drag marks the field touched, so its error can show. Reactive and template-driven forms bind to its checked model directly, as Angular 22 does for any component with one. See Forms.

API

UiSwitch

InputTypeDefaultDescription
checkedbooleanfalseWhether it's on. Supports [(checked)].
disabledbooleanfalseDims the switch and ignores taps and drags.
variant'default' | 'glass''default''glass' draws each platform's own switch.
tintstring—The track's color while it's on, such as 'var(--brand)'.
accessibility-labelstring—What a screen reader calls it, such as 'Wi-Fi'.
classstring''Extra Tailwind classes for the switch.
OutputTypeDescription
changedbooleanEmits the new state after a tap or drag changes it.
checkedChangebooleanEmits the new state, for [(checked)].
touchvoidEmits after each tap or drag, for forms: the field counts as touched.

UiSwitch also has a public toggle() method, which does nothing while disabled.

Accessibility

  • A screen reader reads it as a button with its label and an "On" or "Off" value, in the words of provideAccessibilityWords() when the app gives its own. Android's reads it as a switch. Give it an accessibility-label, since the label beside it is a separate element.
  • Reduce Motion: the thumb jumps across instead of sliding, and turns to glass and back without growing.
  • Reduce Transparency: iOS makes its own lens opaque. On Android and the web, the solid thumb grows instead of turning to glass.
  • Slider: a value in a range, whose thumb turns to glass too
  • Checkbox: for agreeing or picking options in a form
  • Toggle: a button that stays pressed
  • Glass: the Liquid Glass the lens draws
  • Label