Skip to content

    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

    Props

    • orientation
    • dir
    • history
    import { IconArrowBackUp, IconArrowForwardUp, IconBold, IconItalic, IconUnderline } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    import { Toolbar, ToolbarSeparator } from "@/components/ui/toolbar"
    
    <Toolbar aria-label="Text formatting">
      <ToggleGroup type="multiple" aria-label="Marks" size="sm" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
        <ToggleGroupItem value="bold" aria-label="Bold" iconOnly>
          <IconBold size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="italic" aria-label="Italic" iconOnly>
          <IconItalic size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="underline" aria-label="Underline" iconOnly>
          <IconUnderline size={16} />
        </ToggleGroupItem>
      </ToggleGroup>
      <ToolbarSeparator />
      <Button variant="ghost" size="sm" iconOnly aria-label="Undo">
        <IconArrowBackUp size={16} />
      </Button>
      <Button variant="ghost" size="sm" iconOnly aria-label="Redo">
        <IconArrowForwardUp size={16} />
      </Button>
    </Toolbar>

    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.

    • horizontaldefault

    • vertical

    import { IconArrowBackUp, IconArrowForwardUp, IconBold, IconItalic, IconUnderline } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    import { Toolbar, ToolbarSeparator } from "@/components/ui/toolbar"
    
    <Toolbar aria-label="Text formatting">
      <ToggleGroup type="multiple" aria-label="Marks" size="sm" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
        <ToggleGroupItem value="bold" aria-label="Bold" iconOnly>
          <IconBold size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="italic" aria-label="Italic" iconOnly>
          <IconItalic size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="underline" aria-label="Underline" iconOnly>
          <IconUnderline size={16} />
        </ToggleGroupItem>
      </ToggleGroup>
      <ToolbarSeparator />
      <Button variant="ghost" size="sm" iconOnly aria-label="Undo">
        <IconArrowBackUp size={16} />
      </Button>
      <Button variant="ghost" size="sm" iconOnly aria-label="Redo">
        <IconArrowForwardUp size={16} />
      </Button>
    </Toolbar>
    <Toolbar aria-label="Text formatting" orientation="vertical">
      <ToggleGroup type="multiple" aria-label="Marks" orientation="vertical" size="sm" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
        <ToggleGroupItem value="bold" aria-label="Bold" iconOnly>
          <IconBold size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="italic" aria-label="Italic" iconOnly>
          <IconItalic size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="underline" aria-label="Underline" iconOnly>
          <IconUnderline size={16} />
        </ToggleGroupItem>
      </ToggleGroup>
      <ToolbarSeparator />
      <Button variant="ghost" size="sm" iconOnly aria-label="Undo">
        <IconArrowBackUp size={16} />
      </Button>
      <Button variant="ghost" size="sm" iconOnly aria-label="Redo">
        <IconArrowForwardUp size={16} />
      </Button>
    </Toolbar>

    Examples

    Text formatting

    A ToggleGroup for the marks, separate buttons for undo and redo. One Tab stop for the whole row.

    import { IconArrowBackUp, IconArrowForwardUp, IconBold, IconItalic, IconUnderline } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    import { Toolbar, ToolbarSeparator } from "@/components/ui/toolbar"
    
    <Toolbar aria-label="Text formatting">
      <ToggleGroup type="multiple" aria-label="Marks" size="sm" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
        <ToggleGroupItem value="bold" aria-label="Bold" iconOnly>
          <IconBold size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="italic" aria-label="Italic" iconOnly>
          <IconItalic size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="underline" aria-label="Underline" iconOnly>
          <IconUnderline size={16} />
        </ToggleGroupItem>
      </ToggleGroup>
      <ToolbarSeparator />
      <Button variant="ghost" size="sm" iconOnly aria-label="Undo">
        <IconArrowBackUp size={16} />
      </Button>
      <Button variant="ghost" size="sm" iconOnly aria-label="Redo">
        <IconArrowForwardUp size={16} />
      </Button>
    </Toolbar>

    Vertical

    A column of tools beside a canvas, moved through with Up and Down.

    import { IconPencil, IconPointer, IconSquare, IconTrash } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    import { Toolbar, ToolbarSeparator } from "@/components/ui/toolbar"
    
    <Toolbar aria-label="Drawing tools" orientation="vertical">
      <ToggleGroup type="single" defaultValue="select" aria-label="Tool" orientation="vertical" size="sm" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
        <ToggleGroupItem value="select" aria-label="Select" iconOnly>
          <IconPointer size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="pen" aria-label="Pen" iconOnly>
          <IconPencil size={16} />
        </ToggleGroupItem>
        <ToggleGroupItem value="shape" aria-label="Shape" iconOnly>
          <IconSquare size={16} />
        </ToggleGroupItem>
      </ToggleGroup>
      <ToolbarSeparator />
      <Button variant="ghost" size="sm" iconOnly aria-label="Delete">
        <IconTrash size={16} />
      </Button>
    </Toolbar>

    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

    NameTypeValuesDefaultDescription
    orientationenumhorizontal | verticalhorizontalhorizontal: a row, moved through with Left and Right. vertical: a column, moved through with Up and Down.
    loopboolean-trueWraps from the last control to the first and back.
    direnumltr | rtlltrWriting direction of the arrow keys, read from the page when left out. RTL reverses Left and Right.

    Slots

    NameRequiredDescription
    controlsyesButtons, Toggles, ToggleGroups, ToolbarGroups and ToolbarSeparators, in reading order. Use size sm for a dense toolbar.

    Anatomy

    PartDescription
    rootThe toolbar: a row (or column) of controls with gap-xs. It sizes to its content.
    groupToolbarGroup: a named cluster of controls with the same gap.
    separatorToolbarSeparator: a 1px line in the divider color that runs across the toolbar, with spacing-2xs on each side.

    Accessibility

    Role: toolbar

    KeysAction
    TabEnters the toolbar at the control used last, then leaves it.
    ArrowLeft, ArrowRightIn a horizontal toolbar, moves to the previous or next control, follows the writing direction, skips disabled controls and wraps at the ends.
    ArrowUp, ArrowDownDoes the same in a vertical toolbar.
    Home, EndMoves to the first or last control.
    Space, EnterPresses 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.json

    Run 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.