Toggle
A button that stays pressed: bold in a toolbar, a filter chip, a view mode.
Distinct from Switch, which is a form control with an on and an off state and
belongs next to a label. A toggle is a button, announces itself with
aria-pressed, and lives in a toolbar rather than a form.
Live Examples
View Code
ToggleGroup
View Code
Import
import { Toggle, ToggleGroup, ToggleGroupItem } from "@jarllyng/nostromo";Props
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
pressed | boolean | - | Controlled state |
defaultPressed | boolean | false | Uncontrolled initial state |
onPressedChange | (pressed: boolean) => void | - | Fired on change |
variant | "default" | "outline" | "default" | Styling |
size | "sm" | "default" | "lg" | "default" | Control size |
disabled | boolean | false | Not interactive |
ToggleGroup
type is required and picks the behaviour: "single" keeps one selected and
gives you a string, "multiple" allows several and gives you an array.
variant and size set on the group reach the items through context, so an item
still gets the group’s styling when it is wrapped in your own markup. An item can
override either one.
An accessible name is worth writing
An icon-only toggle has no text for a screen reader to announce, so give it
aria-label. The examples above do it for every one.
Related
Switch for a form field, Checkbox when the answer is part of a form’s data,
Button when it does not stay pressed.