Reka UI logoReka
backdrop
Components

Toolbar

A container for grouping a set of controls, such as buttons, Toolbar groups or dropdown menus.

Features

  • Full keyboard navigation.

Installation

Install the component from your command line.

sh
$ npm add reka-ui

Anatomy

Import the component.

vue
<script setup lang="ts">
import {
  ToolbarButton,
  ToolbarLink,
  ToolbarRoot,
  ToolbarSeparator,
  ToolbarToggleGroup,
  ToolbarToggleItem,
} from 'reka-ui'
</script>

<template>
  <ToolbarRoot>
    <ToolbarButton />
    <ToolbarSeparator />
    <ToolbarLink />
    <ToolbarToggleGroup>
      <ToolbarToggleItem />
    </ToolbarToggleGroup>
  </ToolbarRoot>
</template>

API Reference

Root

Contains all the toolbar component parts.

Data AttributeValue
[data-orientation]"vertical" | "horizontal"

Button

A button item.

Data AttributeValue
[data-orientation]"vertical" | "horizontal"

A link item.

ToggleGroup

A set of two-state buttons that can be toggled on or off.

Data AttributeValue
[data-orientation]"vertical" | "horizontal"

ToggleItem

An item in the group.

Data AttributeValue
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled
[data-orientation]"vertical" | "horizontal"

Separator

Used to visually separate items in the toolbar. It runs perpendicular to the toolbar: a horizontal toolbar renders a vertical separator (data-orientation="vertical", aria-orientation="vertical"), and a vertical toolbar a horizontal one.

Data AttributeValue
[data-orientation]"vertical" | "horizontal"

Examples

Use with other primitives

All our primitives which expose a Trigger part, such as Dialog, AlertDialog, Popover, DropdownMenu can be composed within a toolbar by using the asChild prop.

Here is an example using our DropdownMenu primitive.

vue
<script setup lang="ts">
import {
  DropdownMenuContent,
  DropdownMenuRoot,
  DropdownMenuTrigger,
  ToolbarButton,
  ToolbarLink,
  ToolbarRoot,
  ToolbarSeparator,
  ToolbarToggleGroup,
  ToolbarToggleItem,
} from 'reka-ui'
</script>

<template>
  <ToolbarRoot>
    <ToolbarButton>Action 1</ToolbarButton>
    <ToolbarSeparator />
    <DropdownMenuRoot>
      <ToolbarButton as-child>
        <DropdownMenuTrigger>Trigger</DropdownMenuTrigger>
      </ToolbarButton>
      <DropdownMenuContent>…</DropdownMenuContent>
    </DropdownMenuRoot>
  </ToolbarRoot>
</template>

Real-world examples

  • Toolbar Rich Text: A formatting toolbar combining ToggleGroup, DropdownMenu and Tooltip under one roving focus ring.

Accessibility

Uses roving tabindex to manage focus movement among items.

Keyboard Interactions

KeyDescription
Tab
Moves focus to the first item in the group.
Space
Activates/deactivates the item.
Enter
Activates/deactivates the item.
ArrowDown
Moves focus to the next item depending on orientation.
ArrowRight
Moves focus to the next item depending on orientation.
ArrowUp
Moves focus to the previous item depending on orientation .
ArrowLeft
Moves focus to the previous item depending on orientation .
Home
Moves focus to the first item.
End
Moves focus to the last item.

In a right-to-left layout (dir="rtl" on ToolbarRoot, or on a ConfigProvider), ArrowLeft moves to the next item and ArrowRight to the previous one, in a horizontal toolbar. See Internationalization.

Headless composable

useToolbar returns the root and link part surfaces and getButtonSurface() for each button: role="toolbar", aria-orientation and the direction. Moving focus between the items with the arrow keys comes from a RovingFocusGroup that the components render. It is pure, so it can be called outside setup(). The composable is experimental; see Headless composables.