Skip to content

ComponentsButtons

Toolbar

A row or column of buttons, toggles and menus that acts as a single tab stop, with arrow-key navigation between controls. Includes groups, separators that follow the orientation, and plain, outline and floating styles.

React AriaSource

Installation

pnpm dlx shadcn@latest add @desyne/toolbar

The CLI installs dependencies and any other components this one uses.

Usage

tsx
import { Toolbar, ToolbarGroup, ToolbarSeparator } from "@/components/ui/toolbar";
tsx
<Toolbar aria-label="Text formatting">
  <ToolbarGroup aria-label="Style">
    <ToggleButton aria-label="Bold"><BoldIcon /></ToggleButton>
    <ToggleButton aria-label="Italic"><ItalicIcon /></ToggleButton>
  </ToolbarGroup>
  <ToolbarSeparator />
  <Button variant="ghost" size="icon-sm" aria-label="Insert link"><LinkIcon /></Button>
</Toolbar>

Put any Button, Toggle Button, Toggle Button Group or Menu trigger inside. The toolbar doesn't style its children, so pick ghost buttons and a small size to match.

When to use

  • Toolbar — a set of related commands for one area: editor formatting, canvas tools, bulk actions on selected rows, a document header.
  • A plain flex row of buttons — two or three unrelated actions such as Cancel and Save. Those should each be tab stops.
  • Toggle Button Group — a single choice or multi-choice set on its own. Inside a toolbar it becomes one of the toolbar's groups.
  • Menu — when commands don't fit, move the rest behind a "More" menu trigger in the toolbar.

Anatomy

tsx
<Toolbar>                 {/* role="toolbar" */}
  <ToolbarGroup>          {/* role="group" */}
    <Button />
  </ToolbarGroup>
  <ToolbarSeparator />    {/* role="separator", perpendicular to the toolbar */}
  <MenuTrigger />
</Toolbar>
PartRendersNotes
Toolbar<div role="toolbar">React Aria Toolbar. Sets aria-orientation and manages arrow-key focus. data-orientation drives the layout.
ToolbarGroup<div role="group">Groups related controls. Label it with aria-label.
ToolbarSeparator<div role="separator">A vertical line in a horizontal toolbar and a horizontal line in a vertical one, with matching aria-orientation.

Examples

Vertical

orientation="vertical" stacks the controls, for tool palettes on a canvas. Up and down arrows move focus. Separators turn horizontal on their own. Pass orientation="vertical" to a nested ToggleButtonGroup too.

Tool: Select

Zoom: 100%

Variants

plain (default) has no frame, for headers and editor chrome. outline draws a bordered bar on the card surface. floating uses the popover surface and a larger shadow, for bars that hover over content.

plain
outline
floating

Bulk actions

A floating toolbar for actions on selected rows, with a live count. Keep text fields such as search outside the toolbar: the toolbar uses ← and → to move focus, which would stop the cursor moving inside the input.

With a menu

A Menu trigger works like any other button in the toolbar: arrow keys reach it, and Enter, Space or ↓ opens it. Disabled buttons are skipped by arrow keys.

Arrow keys move between controls.

Accessibility

  • The toolbar is one tab stop. Tab moves focus into it (to the last focused control) and out of it; arrow keys move between controls.
  • Every toolbar needs an accessible name: aria-label or aria-labelledby. Label each ToolbarGroup too, so screen readers announce "Alignment, group" when focus enters it.
  • Icon-only buttons need aria-label. Add a Tooltip with the same text (and the shortcut) for sighted users.
  • Use ToggleButton for on/off formatting, so the pressed state is announced, and ToggleButtonGroup with selectionMode="single" for mutually exclusive options such as alignment.
  • In right-to-left locales, ← and → are reversed in a horizontal toolbar.

Keyboard

KeyAction
Tab / Shift+TabMoves focus into or out of the toolbar
→ / ←Next / previous control (horizontal)
↓ / ↑Next / previous control (vertical)
Enter / SpaceActivates the focused control

Styling

Data attributes

AttributeOnPresent when
data-orientationToolbarAlways: horizontal or vertical
data-variantToolbarAlways: plain, outline or floating

Data slots

SlotElement
data-slot="toolbar"Root
data-slot="toolbar-group"A group
data-slot="toolbar-separator"A separator

A horizontal toolbar scrolls sideways when it's wider than its container. To wrap instead, pass className="flex-wrap overflow-visible".

API Reference

Toolbar

Prop

Type

Also accepts every prop of React Aria's Toolbar.

ToolbarGroup

Prop

Type

Also accepts every prop of React Aria's Group.

ToolbarSeparator

Takes React Aria's Separator props. orientation is set from the toolbar; pass it only to override.

  • Toggle Button Group — exclusive or multiple toggles, often a toolbar group.
  • Menu — overflow commands behind a trigger.
  • Tooltip — labels for icon buttons.