Toolbar
A row of controls that act on one thing, such as the formatting buttons above an editor or the actions above a canvas. It holds Buttons, Toggles and ToggleGroups and takes one Tab stop; the arrow keys move between its controls.
Preview
Usage
When to use
- Group the controls that act on one thing, such as text formatting above an editor or tools beside a canvas.
- Give a row of icon buttons one Tab stop, so keyboard users move through it with the arrow keys.
When not to use
- Pick one option from a few that stays selected. Use ToggleGroup.
- Move between pages or sections. Use Tabs.
- Offer actions for one item in a list. Use DropdownMenu.
Variants
orientation
horizontal: a row, moved through with Left and Right. vertical: a column, moved through with Up and Down.
Examples
Text formatting
A ToggleGroup for the marks, separate buttons for undo and redo. One Tab stop for the whole row.
Vertical
A column of tools beside a canvas, moved through with Up and Down.
Do and don't
Do
- Give every icon-only control a name and a Tooltip.
- Group related controls with ToolbarGroup and split the groups with ToolbarSeparator.
- Use one size for every control in the toolbar, sm in dense editors.
Don't
- Do not put a long form in a toolbar. Use a Card or a Dialog.
- Do not use a toolbar for page navigation. Use Tabs or Navbar.
- Do not nest one toolbar inside another.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| orientation | enum | horizontal | vertical | horizontal | horizontal: a row, moved through with Left and Right. vertical: a column, moved through with Up and Down. |
| loop | boolean | - | true | Wraps from the last control to the first and back. |
| dir | enum | ltr | rtl | ltr | Writing direction of the arrow keys, read from the page when left out. RTL reverses Left and Right. |
Slots
| Name | Required | Description |
|---|---|---|
| controls | yes | Buttons, Toggles, ToggleGroups, ToolbarGroups and ToolbarSeparators, in reading order. Use size sm for a dense toolbar. |
Anatomy
| Part | Description |
|---|---|
| root | The toolbar: a row (or column) of controls with gap-xs. It sizes to its content. |
| group | ToolbarGroup: a named cluster of controls with the same gap. |
| separator | ToolbarSeparator: a 1px line in the divider color that runs across the toolbar, with spacing-2xs on each side. |
Accessibility
Role: toolbar
| Keys | Action |
|---|---|
| Tab | Enters the toolbar at the control used last, then leaves it. |
| ArrowLeft, ArrowRight | In a horizontal toolbar, moves to the previous or next control, follows the writing direction, skips disabled controls and wraps at the ends. |
| ArrowUp, ArrowDown | Does the same in a vertical toolbar. |
| Home, End | Moves to the first or last control. |
| Space, Enter | Presses the focused control. |
- A toolbar requires aria-label or aria-labelledby.
- Only one control has tabIndex 0: the one focused last. The rest have -1, so Tab leaves the toolbar in one step.
- A ToggleGroup inside leaves its arrow keys to the toolbar, so the whole row stays one Tab stop.
- A text field inside keeps its own arrow keys; Tab moves out of it.
- ToolbarGroup is a named group of controls; ToolbarSeparator is a separator with aria-orientation across the toolbar.
Install
npx werewolf-ui add https://www.werewolf-ui.dev/r/toolbar.jsonRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.