Toggle
A button that stays pressed until tapped again, on its own or in a group where one or several are pressed.
Installation
Toggle imports class-variance-authority (see Installation).
Usage
- A pressed toggle gets the accent background.
- Toggles don't wrap their content, so put a
<text>element inside. pressedhere is the on/off state, not a tap event like Button'spressed.
Toggle group, one at a time
valueis an array even in single mode, such as['left']. Bind it tosignal<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
Each tap adds or removes that item's value.
Segmented control
The platform's own segmented control, for picking one of a few options:
- 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 pointstext-foregroundat a color that reads on it. sizeand the other variants don't apply. The control has the platform's height: 32pt on iOS, 40dp on Android.
What each platform draws:
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
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
A group passes its variant and size to every item.
Disabled
Forms
value is a model(), so it works with every Angular forms API:
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
UiToggleGroup
UiToggleGroupItem
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,selectedwhile 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: 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
