Components · Inputs
ToggleGroup
A compact row of toggle buttons in a gray track, each one on or off on its own, or one of them or none; a pressed button is a yellow sticker.
Also called Toggle buttons, Toolbar toggles
import { ToggleGroup } from "@botiverse/raft-ui";A toggle group is a row of buttons in a gray track that people press on and off: Bold, Italic and Underline, or a row of filters, each selectable on its own (Built from existing parts). With multiple, any number can be on; without it, one or none. A pressed button is a yellow sticker.
When to use
The full table is in Choosing a component.
Anatomy
ToggleGroup: the track, infill-muted. Itsvalueis the list of pressed items. Required.ToggleGroupItem: one 32px button (34px with a mouse, the control height), identified by itsvalue. Required, at least 2.- An icon: optional, 16px. It can stand alone (
aria-labelrequired, see Accessibility). ToggleGroupLabel: the visible label. It truncates when the row is too narrow.
- An icon: optional, 16px. It can stand alone (
Variants
States
Behavior
- A horizontal group wraps its items onto a new row when they don't fit, and never grows wider than its container.
- Pressing a pressed item turns it off, in both variants.
- On a touch screen an item toggles when the finger lifts, so a tap that stops a scrolling list still toggles (Switching on finger lift).
- Items sit 3px inside the track and 3px apart, like the segments of a SegmentedControl.
- Items are 32px high (34px with a mouse) and don't extend their hit area to 44px. On touch screens that is below the hit target.
Content
- Label each item with what it turns on, in sentence case: Bold, Numbered list (Writing).
Accessibility
ToggleGroupwraps the Base UI ToggleGroup and eachToggleGroupItemthe Base UI Toggle: every item is a button witharia-pressed, and the arrow keys move focus between items in the direction oforientation, wrapping at the ends (loopFocus).- Name the group with
aria-labelafter what it controls: "Text formatting", "Text alignment". - Give every icon-only item an
aria-label("Align left"), and hide its icon (aria-hidden).
Rules
- Don't use a toggle group to switch views or sections: one view is always shown, and a toggle group can be left with none. Use a SegmentedControl or Tabs.
API
ToggleGroup
Also takes the attributes of its element.
ToggleGroupItem
Also takes the attributes of its element.
ToggleGroupLabel
Takes the attributes of its element.
Related
Changes
- 0.3.0 · AddedGraduated
ProfilePanelandToggleGroupto the stable package entry point.