Toolbar

A row of controls with one tab stop: Tab reaches the toolbar, the arrow keys move between its buttons, Home and End jump to the ends. Built on ui-sdk's Toolbar. Icon buttons show their label as a tooltip; pressed makes a button a toggle. The Rich text field's toolbar is this one.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

label
pressed
shortcut
disabled
icon

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it for a row of related commands that should be one tab stop, like the rich text field's formatting buttons.
DoName it with aria-label, like Formatting, and give every ToolbarButton a label. An icon-only button shows its label as a tooltip.
DoPass shortcut when the command has one, like mod+b for Bold, so the tooltip shows it.
DoSplit related commands with ToolbarGroup and ToolbarSeparator, like text styles and lists. Set pressed on a button that toggles, like Bold.
Don'tUse it for two or three standalone actions, like Export as CSV or PDF. Use ButtonGroup, where each button is its own tab stop.

Props

Toolbar

PropTypeDefaultDescription
aria-label *string—Names the toolbar, like "Formatting".
childrenReactNode—What it shows inside.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

ToolbarButton

PropTypeDefaultDescription
iconReactNode—The 14 px icon. With no children, the button is icon only.
label *string—Names the button. An icon-only button also shows it as its tooltip.
childrenReactNode—Visible text after the icon.
pressedboolean—Makes it a toggle that stays pressed, like Bold.
shortcutstring—A keyboard shortcut for the tooltip, like "mod+b".
onClick() => void—Runs the command.
disabledboolean—Shows it as unavailable and stops it responding.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

ToolbarGroup

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

ToolbarSeparator

No props of its own.

Code

What the playground shows, ready to copy.

import { PlusIcon, Toolbar, ToolbarButton } from "@leap-crm/design-system";

<Toolbar aria-label="Formatting">
  <ToolbarButton label="Bold" icon={<PlusIcon />} />
</Toolbar>

Formatting

Two groups of toggles split by a rule. Tab in, then use the arrow keys; Bold, Italic and Underline toggle.

With text

A button with children shows its text and needs no tooltip.

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { AlignCenter, AlignLeft, AlignRight, Bold, Download, Italic, Printer, Underline } from "lucide-react";

import { useState } from "react";

import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@leap-crm/design-system";

const alignments = [
  { value: "left", icon: <AlignLeft /> },
  { value: "center", icon: <AlignCenter /> },
  { value: "right", icon: <AlignRight /> },
];

function Formatting() {
  const [marks, setMarks] = useState<string[]>(["bold"]);
  const [align, setAlign] = useState("left");
  const toggle = (mark: string) =>
    setMarks(current =>
      current.includes(mark)
        ? current.filter(m => m !== mark)
        : [...current, mark],
    );
  return (
    <Toolbar
      aria-label="Formatting"
      className="border-neutral-border w-fit rounded-md border p-1"
    >
      <ToolbarGroup aria-label="Text style">
        <ToolbarButton
          icon={<Bold />}
          label="Bold"
          shortcut="mod+b"
          pressed={marks.includes("bold")}
          onClick={() => toggle("bold")}
        />
        <ToolbarButton
          icon={<Italic />}
          label="Italic"
          shortcut="mod+i"
          pressed={marks.includes("italic")}
          onClick={() => toggle("italic")}
        />
        <ToolbarButton
          icon={<Underline />}
          label="Underline"
          shortcut="mod+u"
          pressed={marks.includes("underline")}
          onClick={() => toggle("underline")}
        />
      </ToolbarGroup>
      <ToolbarSeparator />
      <ToolbarGroup aria-label="Alignment">
        {alignments.map(({ value, icon }) => (
          <ToolbarButton
            key={value}
            icon={icon}
            label={`Align ${value}`}
            pressed={align === value}
            onClick={() => setAlign(value)}
          />
        ))}
      </ToolbarGroup>
    </Toolbar>
  );
}

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TabLands on the toolbar once, on the item focused last, and Tab again leaves it.
ArrowRightArrowLeftMove through every item, wrapping at the ends.
EnterSpacePress the focused item. Arrow keys never press a toggle.