Toolbar

A row of controls with one tab stop and arrow-key focus.

Source
$npx @dinachi/cli@latest add toolbar
orientation
disabled
ToolbarLink
ToolbarInput

Usage

import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@/components/ui/toolbar"

export function FormatBar() {
  return (
    <Toolbar aria-label="Formatting">
      <ToolbarGroup>
        <ToolbarButton>Bold</ToolbarButton>
        <ToolbarButton>Italic</ToolbarButton>
      </ToolbarGroup>
      <ToolbarSeparator />
      <ToolbarButton>Clear</ToolbarButton>
    </Toolbar>
  )
}

Examples

Buttons in groups, separators and a link.
import { Toolbar, ToolbarButton, ToolbarSeparator, ToolbarGroup, ToolbarLink } from '@/components/ui/toolbar';
import { Bold, Italic, Underline, Link, AlignLeft, AlignCenter, AlignRight } from 'lucide-react';

export function Example() {
  return (
    <Toolbar>
      <ToolbarGroup>
        <ToolbarButton aria-label="Bold">
          <Bold className="h-4 w-4" />
        </ToolbarButton>
        <ToolbarButton aria-label="Italic">
          <Italic className="h-4 w-4" />
        </ToolbarButton>
        <ToolbarButton aria-label="Underline">
          <Underline className="h-4 w-4" />
        </ToolbarButton>
      </ToolbarGroup>
      <ToolbarSeparator />
      <ToolbarGroup>
        <ToolbarButton aria-label="Align left">
          <AlignLeft className="h-4 w-4" />
        </ToolbarButton>
        <ToolbarButton aria-label="Align center">
          <AlignCenter className="h-4 w-4" />
        </ToolbarButton>
        <ToolbarButton aria-label="Align right">
          <AlignRight className="h-4 w-4" />
        </ToolbarButton>
      </ToolbarGroup>
      <ToolbarSeparator />
      <ToolbarLink href="#">
        <Link className="mr-1 h-4 w-4" />
        Insert Link
      </ToolbarLink>
    </Toolbar>
  );
}

Notes

Toggles

Pass a Toggle to ToolbarButton through render; wrap several in a ToggleGroup for a shared value.

<ToggleGroup defaultValue={["bold"]} multiple>
  <ToolbarButton render={<Toggle value="bold" />} aria-label="Bold">
    <Bold className="h-4 w-4" />
  </ToolbarButton>
</ToggleGroup>

Vertical toolbars

Separators do not follow the toolbar's orientation. With orientation="vertical", pass orientation="horizontal" to each ToolbarSeparator and add className="inline-flex flex-col".

API

orientation"horizontal" | "vertical" = "horizontal"
Which arrow keys move focus.
loopFocusboolean = true
Wraps focus from the last item to the first.
disabledboolean = false
Disables every item.

Accessibility

  • Role toolbar. Name it with aria-label when a page has several.
  • One item is in the tab order; arrow keys reach the rest.
  • Icon-only buttons need an aria-label each.
  • Disabled buttons and inputs stay focusable by default.