Toolbar

A row of related controls (formatting buttons, view options, a menu) that is a single Tab stop; the arrow keys move between its controls.

BetaSource

Import

import { Toolbar } from "@meridui/react";

Anatomy

<Toolbar.Root aria-label="…">
  <Toolbar.Group aria-label="…">
    <Toolbar.Button />
  </Toolbar.Group>
  <Toolbar.Separator />
  <Toolbar.Link />
</Toolbar.Root>
  • Root is the role="toolbar" element. Give it an aria-label.
  • Button and Link are the items the arrow keys move between. With asChild any element joins, e.g. a DropdownMenu.Trigger.
  • Group (role="group") and Separator organise the items.

Examples

Toggle buttons

A formatting toggle is a Toolbar.Button with aria-pressed; the pressed state gets the accent-soft fill. For a set where only one can be on, keep the state in your component.

Wrap a Toolbar.Button in DropdownMenu.Trigger asChild, as in the example above. The menu opens with Enter, Space or ArrowDown; closing it returns focus to the toolbar.

API reference

Root

Accepts every <div> attribute.

PropTypeDefaultDescription
aria-labelstring–Accessible name; required unless you pass aria-labelledby.
orientation"horizontal" | "vertical""horizontal"Layout and arrow-key axis.
loopbooleantrueWrap from the last item to the first.
refRef<HTMLDivElement>–Forwarded ref.

Button

Accepts every <button> attribute.

PropTypeDefaultDescription
disabledbooleanfalseSets aria-disabled and blocks clicks; skipped by the arrow keys.
asChildbooleanfalseRender the single child element instead of a <button>.
refRef<HTMLButtonElement>–Forwarded ref.

Link accepts every <a> attribute and asChild. Group and Separator accept every <div> attribute; the separator's aria-orientation is set perpendicular to the toolbar.

Styling

ClassElement
.mrd-toolbarRoot
.mrd-toolbar__groupGroup
.mrd-toolbar__button, .mrd-toolbar__linkButton and Link (unless asChild)
.mrd-toolbar__separatorSeparator
AttributeOnValues
data-orientationRoothorizontal, vertical
aria-pressedButtontrue gets the pressed style
data-disabledButtonpresent when disabled

Accessibility

Follows the WAI-ARIA Toolbar pattern with a roving tabindex: only one item is in the Tab sequence, and the toolbar remembers the last focused item. Right and Left follow reading direction in RTL.

KeyAction
TabMove into the toolbar (to the last focused item) or out of it.
ArrowRightNext item, wrapping (ArrowDown when vertical).
ArrowLeftPrevious item, wrapping (ArrowUp when vertical).
HomeFirst item.
EndLast item.
EnterSpaceActivate the focused button.

Guidelines

Do

Group three or more related controls that act on the same thing, like the text in an editor.

Avoid

Wrap a page's unrelated buttons in a toolbar just for the look; each would lose its own Tab stop.