Skip to content
Alea0.1

Actions

ToggleGroup and Toolbar

Toggle buttons where one or several can be on, and a toolbar that is one Tab stop with arrow keys inside.

Ant Design: Segmented (multiple)

import { ToggleGroup, Toolbar } from '@alea/ui';

Examples

Formatting toolbar

One Tab stop; arrows move. Bold, italic and underline toggle independently, alignment is one of three.

With labels

A view switcher with icons and words.

Props

ToggleGroup props

A set of toggle buttons, one or several on: bold/italic, view modes, filters (Radix ToggleGroup, MUI ToggleButtonGroup).

PropTypeDefaultDescription
aria-labelrequiredstring-What the group controls, for screen readers ("Text style").
itemsrequired{ id: Key; label: string; icon?: ReactNode; isDisabled?: boolean | undefined; }[]-Buttons: id, label, and an icon. With iconOnly the label becomes the accessible name.
classNamestring-Extra class names for the root element.
defaultValueKey[]-The pressed ids to start with.
iconOnlyboolean-Show only the icons.
onChange((keys: Key[]) => void)-Called with the pressed ids.
selectionMode"single" | "multiple"'single'single (like radio buttons) or multiple (like checkboxes). Default single.
size"sm" | "md"'md'sm (26 px) or md (32 px, default).
valueKey[]-The pressed ids (controlled).

Toolbar props

A row of controls that is one Tab stop; arrow keys move inside it (editor toolbars, table tools).

PropTypeDefaultDescription
aria-labelstring-Defines a string value that labels the current element. (React Aria)
childrenChildrenOrFunction<DisclosureGroupRenderProps>-The children of the component. A function may be provided to alter the children based on component state. (React Aria)
classNameClassNameOrFunction<ToolbarRenderProps>-The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. (React Aria)
orientation"horizontal" | "vertical"-The orientation of the entire toolbar. (React Aria)
styleStyleOrFunction<DisclosureGroupRenderProps>-The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. (React Aria)

Accessibility

  • Each toggle is a button with aria-pressed.
  • Icon-only toggles take their label as the accessible name.
  • Toolbar has role toolbar: one Tab stop, arrow keys move inside.

Keyboard

KeyDoes
TabEnters and leaves the toolbar
Arrow Left / RightMove between controls
Space or EnterToggles

Do and don't

Do

  • Use single for exclusive options (alignment) and multiple for independent ones (bold, italic).
  • Give icon-only toggles labels.

Don't

  • Don't use it for navigation: use Tabs.
  • Don't mix single and multiple behavior in one group.
Tested with axe, keyboard and screen reader roles