> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Toggle

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


## Installation

```bash
npx @blotch/dolan add toggle
```

```typescript
import {
  UiToggle,
  UiToggleGroup,
  UiToggleGroupItem,
} from '../components/ui/toggle';
```

Toggle imports `class-variance-authority` (see [Installation](/dolan/index.md#installation)).

:::tip
Toggle depends on `segmented-control`, which draws the segmented variant and builds on [Glass](/dolan/glass.md) and [Icon](/dolan/icon.md). `dolan add` installs them automatically.
:::

## Usage

```typescript title="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

```angular-html
<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](/dolan/radio-group.md) if one option must always stay selected.

### Toggle group, several at once

```angular-html
<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:

```angular-html
<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`](/api/angular-lynx/device/haptics.md): 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:

| Platform                                          | Segmented control                                                                                               |
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| iOS 26 and later                                  | A capsule with a white thumb that lifts into Liquid Glass as it slides and while you drag it                    |
| iOS 15 to 25                                      | The control of iOS 13 to 18: a gray track, hairline separators, and a raised thumb that shrinks while held      |
| Android                                           | Material 3 Expressive's connected button group: the selected item filled with the primary color and fully round |
| Android, with [`provideGlass()`](/dolan/glass.md) | The iOS 26 control, its glass without the refraction                                                            |
| [Web preview](/guide/glossary.md#web-preview)     | The 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

```angular-html
<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

```angular-html
<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

```angular-html
<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:

```angular-html
<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](/dolan/switch.md) or a [Checkbox](/dolan/checkbox.md) in a form. See [Forms](/guide/forms.md).

## API

### UiToggle

| Input      | Type                        | Default     | Description                                   |
| ---------- | --------------------------- | ----------- | --------------------------------------------- |
| `pressed`  | `boolean`                   | `false`     | Whether it's pressed. Supports `[(pressed)]`. |
| `variant`  | `'default' \| 'outline'`    | `'default'` | `outline` adds a border.                      |
| `size`     | `'default' \| 'sm' \| 'lg'` | `'default'` | Height and padding.                           |
| `disabled` | `boolean`                   | `false`     | Dims the toggle and ignores taps.             |
| `class`    | `string`                    | `''`        | Extra Tailwind classes for the toggle.        |

| Output          | Type      | Description                             |
| --------------- | --------- | --------------------------------------- |
| `pressedChange` | `boolean` | Emits the new state, for `[(pressed)]`. |

### UiToggleGroup

| Input      | Type                                    | Default     | Description                                                          |
| ---------- | --------------------------------------- | ----------- | -------------------------------------------------------------------- |
| `type`     | `'single' \| 'multiple'`                | `'single'`  | Whether one or several items can be pressed.                         |
| `value`    | `string[]`                              | `[]`        | The pressed items' values. Supports `[(value)]`.                     |
| `variant`  | `'default' \| 'outline' \| 'segmented'` | `'default'` | Style of every item, or the [segmented control](#segmented-control). |
| `size`     | `'default' \| 'sm' \| 'lg'`             | `'default'` | Size of every item.                                                  |
| `disabled` | `boolean`                               | `false`     | Dims every item and ignores taps.                                    |
| `class`    | `string`                                | `''`        | Extra Tailwind classes for the row.                                  |

| Output        | Type       | Description                                                            |
| ------------- | ---------- | ---------------------------------------------------------------------- |
| `valueChange` | `string[]` | Emits the new value, for `[(value)]`.                                  |
| `touch`       | `void`     | Emits when an item is pressed, for forms: the field counts as touched. |

### UiToggleGroupItem

| Input                 | Type     | Default  | Description                                                     |
| --------------------- | -------- | -------- | --------------------------------------------------------------- |
| `value`               | `string` | Required | The value this item adds or removes.                            |
| `accessibility-label` | `string` | —        | What a screen reader says. Makes the item a button (see below). |
| `class`               | `string` | `''`     | 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.

## Related

- [Tabs](/dolan/tabs.md): the segmented control for switching panels
- [Button Group](/dolan/button-group.md): connected buttons for one-off actions
- [Radio Group](/dolan/radio-group.md): one option that always stays selected
- [Switch](/dolan/switch.md): an on/off control for settings
