Toolbar

new

Your app's utility belt. A row or column of buttons, toggles, links and separators. One Tab gets you in, arrow keys do the rest.

Demo

Open Props in the corner of the example to try variant.

Installation

Usage

<script setup lang="ts">
import { Bold, Italic } from '@lucide/vue'

import { Toolbar, ToolbarButton, ToolbarSeparator, ToolbarToggleGroup, ToolbarToggleItem } from '@/components/ui/toolbar'
</script>

<template>
  <Toolbar aria-label="Formatting">
    <ToolbarToggleGroup type="multiple" size="icon-sm">
      <ToolbarToggleItem value="bold" aria-label="Bold"><Bold /></ToolbarToggleItem>
      <ToolbarToggleItem value="italic" aria-label="Italic"><Italic /></ToolbarToggleItem>
    </ToolbarToggleGroup>
    <ToolbarSeparator />
    <ToolbarButton>Share</ToolbarButton>
  </Toolbar>
</template>

Give it an aria-label so screen readers know what it's for.

  • ToolbarButton, ToolbarLink: a regular Button, ghost + neutral by default
  • ToolbarToggleGroup, ToolbarToggleItem: a ToggleGroup with gaps instead of joined edges
  • ToolbarSeparator: a divider

Examples

Vertical

orientation="vertical" stacks the parts and the up and down arrows move focus. Toggle groups and separators follow.

Vertical

Ghost

variant="ghost" drops the frame, for a row of buttons in a card or page header that still moves focus with the arrows.

Ghost

Draft

A ghost toolbar has no frame of its own, so it sits in a card header or a page header as a row of buttons that still moves focus with the arrow keys.

API Reference

Every part accepts class, merged over its base classes.

Data attributes

data-slotAttributesDescription
toolbardata-variant, aria-orientationThe root, a role="toolbar".
toolbar-buttondata-variant, data-color, data-size, data-orientationA Button in the focus order.
toolbar-linkdata-variant, data-color, data-size, data-orientationA link Button in the focus order.
toolbar-separatordata-orientationThe line, carrying the toolbar's orientation.
toolbar-toggle-groupdata-orientation, data-sizeA role="group" of toggle items.
toolbar-toggle-itemdata-state, data-variant, data-color, data-size, data-orientationA toggle item in the focus order.

Keyboard

KeyAction
TabMoves focus into the toolbar, onto the last focused part, and out again.
ArrowLeft / ArrowRightMoves focus between the parts of a horizontal toolbar, wrapping around.
ArrowUp / ArrowDownMoves focus between the parts of a vertical toolbar, wrapping around.
Home / EndMoves focus to the first or last part.
Space / EnterActivates the focused button, link or toggle.

Changelog

  1. registry 0.22.0

    4712efa — A Kbd inside a Button wrapped in TooltipTrigger as-child (or any other as-child trigger) keeps the button's colours, and an InputGroupButton wrapped the same way in a block addon keeps the addon's inset. The trigger's data-slot replaces the child's own, as in shadcn, so Kbd now keys on the <button> element (any button tints it, Toggle and Toolbar items included) and the block addon sets the inset on its children.

    ac9afad — An aria-disabled Toggle, ToggleGroupItem or ToolbarToggleItem ignores click, Enter and Space like an aria-disabled Button, so a toolbar toggle kept focusable for its tooltip no longer changes the model. swallowWhenDisabled moves to @/ui/button, where the three parts share it.

  2. registry 0.21.0

    e5495ef — size works the same way everywhere. Every component exports its size type (AlertSize, BadgeSize, CardSize, CheckboxSize, RadioSize, SwitchSize, EmptySize, InputFloatingSize, ItemSize, ListboxSize, SeparatorSize, SliderSize, StepperSize, TabsSize, TextareaSize, TimelineSize) and the props take it without null; Button-based parts take ButtonSize, Input TextControlSize, SelectTrigger SelectSize and Tree TreeSize. ToggleGroup and ToolbarToggleGroup carry data-size on the group as well. Table's row heights moved into tableSize, so a class on DataTable's ui.table overrides --table-row-h at every size, not only at md.

  3. registry 0.13.0

    93e57a0 — Every size on the control scale is named xs to xl; default and the bare icon are gone. To move over:

    - Button: size="default" becomes size="md", or leave size out; size="icon" becomes size="icon-md". The full set is xs to xl and icon-xs to icon-xl. Toggle, ToggleGroup, ToggleGroupItem, the Toolbar parts, AlertDialogAction, AlertDialogCancel and ToastAction take the same names; Button, Toggle and ToggleGroup default to md, the Toolbar parts keep sm and ToastAction keeps xs. InputGroupButton keeps its own xs, sm, icon-xs and icon-sm, 24 and 32px to fit inside the group, xs by default. Pagination hands its md to Button as it is. Button, Toggle and ToggleGroupItem set data-variant, data-color and data-size even when you leave them at their defaults. - AlertDialogContent: size="default" becomes size="md", still the default; sm is unchanged. The size option of useConfirm's confirm, alert and prompt takes the same names. - Table and DataTable: density becomes size, data-density becomes data-size, and the TableDensity type is now TableSize. sm, md and lg keep their 36, 44 and 52px rows; xs (28px) and xl (60px) are new, and DataTable's virtual row estimates cover them. The cells' padding above and below the text is now --table-cell-py on the table: 8px as before, 3px at xs. At xs, DataTable's sort buttons and expand and group toggles shrink to fit the row. The table-density example is now table-sizes. - DrawerMenu: size takes xs to xl like Menu and reads the control scale, plus room for a thumb. sm, md and lg keep their 40, 48 and 56px rows, padding and icons; xs is 36px and xl 64px. Overriding a --control-* token on :root now resizes DrawerMenu rows as well. - Select and Combobox: the list opens at the trigger's or anchor's size instead of always at md, so <SelectTrigger size="xl"> opens an xl list. size on SelectContent or ComboboxList picks another. Behind an as-child button, set size on ComboboxAnchor to match the button. The Select list now sets its menu variables on SelectContent instead of its viewport, so a class such as [--menu-item-height:2.5rem] on SelectContent reaches the items. - Input, Textarea, InputFloating, SelectTrigger, ComboboxAnchor and Separator set data-size with the default filled in, and the anchor sets data-variant too. With as-child, the anchor leaves the button's own data-variant and data-size alone.

  4. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  5. registry 0.7.0

    07109fb — Toolbar: Toolbar, ToolbarButton, ToolbarLink, ToolbarSeparator, ToolbarToggleGroup and ToolbarToggleItem over Reka UI's toolbar, drawn with Button and ToggleGroup: one tab stop, arrow-key focus, a framed outline or a bare ghost variant.