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/toggle.md.

Toggle

A button that stays pressed until tapped again, on its own or in a group where one or several are pressed.

Installation

npx @blotch/dolan add toggle
import {
  UiToggle,
  UiToggleGroup,
  UiToggleGroupItem,
} from '../components/ui/toggle';

Toggle imports class-variance-authority (see Installation).

Tip

Toggle depends on segmented-control, which draws the segmented variant and builds on Glass and Icon. dolan add installs them automatically.

Usage

src/app/app.ts
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiToggle } from '../components/ui/toggle';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, UiToggle],
  template: `
    <ui-toggle [(pressed)]="bold">
      <text class="text-sm font-bold text-foreground">B</text>
    </ui-toggle>
  `,
})
export class App {
  protected readonly bold = signal(false);
}
  • A pressed toggle gets the accent background.
  • Toggles don't wrap their content, so put a <text> element inside.
  • pressed here is the on/off state, not a tap event like Button's pressed.

Toggle group, one at a time

<ui-toggle-group type="single" [(value)]="alignment">
  <ui-toggle-group-item value="left">
    <text class="text-sm text-foreground">Left</text>
  </ui-toggle-group-item>
  <ui-toggle-group-item value="center">
    <text class="text-sm text-foreground">Center</text>
  </ui-toggle-group-item>
</ui-toggle-group>
  • value is an array even in single mode, such as ['left']. Bind it to signal<string[]>(['left']).
  • Tapping the pressed item again clears the selection to []. Use Radio Group if one option must always stay selected.

Toggle group, several at once

<ui-toggle-group type="multiple" [(value)]="formatting">…</ui-toggle-group>

Each tap adds or removes that item's value.

Segmented control

The platform's own segmented control, for picking one of a few options:

<ui-toggle-group variant="segmented" [(value)]="range">
  <ui-toggle-group-item value="day" accessibility-label="Day">
    <text class="text-[13px] text-foreground">Day</text>
  </ui-toggle-group-item>
  <ui-toggle-group-item value="week" accessibility-label="Week">
    <text class="text-[13px] text-foreground">Week</text>
  </ui-toggle-group-item>
  <ui-toggle-group-item value="month" accessibility-label="Month">
    <text class="text-[13px] text-foreground">Month</text>
  </ui-toggle-group-item>
</ui-toggle-group>
  • The selected item has a thumb that slides to the item you tap. You can also drag it across the items: it follows your finger and selects where you let go.
  • The phone ticks when the selection changes, with LynxHaptics: on a tap of another item, and as a dragged thumb crosses onto each item.
  • On iOS 26 the thumb lifts into Liquid Glass while it moves, as UIKit's segmented control does, and settles back into a solid thumb. The thumb is the only glass. The items are plain.
  • One item stays selected. Tapping it again doesn't clear it, unlike the other variants.
  • The items share the group's width. Give one class="flex-[2]" to make it wider. The thumb follows each item's measured width, also after a rotation.
  • Write the item's text text-foreground. On Android the selected item's fill is dark, and the item points text-foreground at a color that reads on it.
  • size and the other variants don't apply. The control has the platform's height: 32pt on iOS, 40dp on Android.

What each platform draws:

PlatformSegmented control
iOS 26 and laterA capsule with a white thumb that lifts into Liquid Glass as it slides and while you drag it
iOS 15 to 25The control of iOS 13 to 18: a gray track, hairline separators, and a raised thumb that shrinks while held
AndroidMaterial 3 Expressive's connected button group: the selected item filled with the primary color and fully round
Android, with provideGlass()The iOS 26 control, its glass without the refraction
Web previewThe iOS 26 control, its glass drawn with WebGL

Android draws Material 3 Expressive's connected button group rather than Material's segmented buttons, which Material 3 Expressive deprecates in its favor. Nothing slides there, as in Material's own group. A press shows Material's state layer.

Several at once

<ui-toggle-group variant="segmented" type="multiple" [(value)]="formats">
  <ui-toggle-group-item value="bold" accessibility-label="Bold">
    <ui-icon name="bold" size="sm" />
  </ui-toggle-group-item>
  …
</ui-toggle-group>

One thumb can't mark several items, so in a multiple group each pressed item draws its own thumb, and nothing slides or drags. On Android each pressed item fills, as Material's connected group does.

Variants and sizes

<ui-toggle variant="outline" size="sm">…</ui-toggle>
<ui-toggle-group variant="outline" size="lg">…</ui-toggle-group>

A group passes its variant and size to every item.

Disabled

<ui-toggle disabled>…</ui-toggle>
<ui-toggle-group type="single" disabled [value]="['left']">…</ui-toggle-group>

Forms

value is a model(), so it works with every Angular forms API:

<ui-toggle-group [formField]="profile.field" />
<ui-toggle-group [formControl]="control" />
<ui-toggle-group [(ngModel)]="value" />

Pressing an item marks the field touched. UiToggleGroup implements Signal Forms' FormValueControl. A single ui-toggle isn't a form control: its state is pressed. Use a Switch or a Checkbox in a form. See Forms.

API

UiToggle

InputTypeDefaultDescription
pressedbooleanfalseWhether it's pressed. Supports [(pressed)].
variant'default' | 'outline''default'outline adds a border.
size'default' | 'sm' | 'lg''default'Height and padding.
disabledbooleanfalseDims the toggle and ignores taps.
classstring''Extra Tailwind classes for the toggle.
OutputTypeDescription
pressedChangebooleanEmits the new state, for [(pressed)].

UiToggleGroup

InputTypeDefaultDescription
type'single' | 'multiple''single'Whether one or several items can be pressed.
valuestring[][]The pressed items' values. Supports [(value)].
variant'default' | 'outline' | 'segmented''default'Style of every item, or the segmented control.
size'default' | 'sm' | 'lg''default'Size of every item.
disabledbooleanfalseDims every item and ignores taps.
classstring''Extra Tailwind classes for the row.
OutputTypeDescription
valueChangestring[]Emits the new value, for [(value)].
touchvoidEmits when an item is pressed, for forms: the field counts as touched.

UiToggleGroupItem

InputTypeDefaultDescription
valuestringRequiredThe value this item adds or removes.
accessibility-labelstring—What a screen reader says. Makes the item a button (see below).
classstring''Extra Tailwind classes for the item.

No outputs.

The file also exports the ToggleVariant, ToggleGroupVariant and ToggleSize types.

Accessibility

  • Give each group item an accessibility-label. The item becomes one button that a screen reader reads by it, selected while pressed (iOS reads the trait). An icon-only item needs one. Without it, a screen reader reads the item's text, with no state.
  • Reduce Motion: the segmented control's thumb jumps to the selected item instead of sliding, and doesn't lift into glass. A drag still moves it with your finger.
  • Reduce Transparency: the thumb stays solid as it moves. Increase Contrast gives it an outline, and Android's items an outline too.
  • Tabs: the segmented control for switching panels
  • Button Group: connected buttons for one-off actions
  • Radio Group: one option that always stays selected
  • Switch: an on/off control for settings