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
src/app/app.ts
- 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.
Variants and sizes
A group passes its variant and size to every item.
Disabled
API
UiToggle
UiToggleGroup
UiToggleGroupItem
No outputs.
The file also exports the ToggleVariant and ToggleSize types.
Related
- Button Group: connected buttons for one-off actions
- Radio Group: one option that always stays selected
- Switch: an on/off control for settings
