Skip to content

Toolbar

Toolbar

A container for a set of controls (APG Toolbar pattern): role="toolbar", one Tab stop, and arrow-key navigation between its controls.

- Works with any children (Buttons, ToggleButtons, links, inputs, value controls such as Checkbox or Dropdown): the focusable controls are found in the DOM, and the Toolbar sets their tabIndex itself (one 0, the rest -1). The type="hidden" input that a named value control renders never counts as a control, and controls that CSS hides are skipped.
- Parts: Toolbar.Button, Toolbar.ToggleButton and Toolbar.RadioButton take the toolbar's size (default 'medium') and the subtle appearance by default; Toolbar.RadioGroup, Toolbar.Group and Toolbar.Divider lay them out. Plain Buttons keep their own defaults.
- State: the pressed Toolbar.ToggleButtons and the checked Toolbar.RadioButton of each group live in checkedValues/defaultCheckedValues, per group name, and every change calls onCheckedValuesChange(checkedValues, details). The state is in the server HTML.
- Left/Right (Up/Down when orientation="vertical") move focus and wrap; Home/End jump to the first/last control; Left/Right are mirrored in RTL. Natively disabled controls are skipped, also when a child disables them on its own; disabledFocusable ones stay in the arrow-key order (APG), so a Tooltip can explain why they are unavailable. The arrows never press a toggle or check a radio: Space, Enter or a click does.
- The radios of a Toolbar.RadioGroup are part of that arrow-key order, and Up/Down (Left/Right in a vertical toolbar) also move among them, wrapping inside the group.
- Tab returns to the last focused control. Focusing a nested composite (radio group, tab list) or a text field, select, slider or spin button keeps the Tab stop where it was.
- Text fields, selects, sliders, spin buttons and editable comboboxes keep their own arrow keys (the caret moves). A Dropdown (select-only combobox) does not: Left/Right move past it. It keeps Up/Down, Home and End for its list, so in a vertical toolbar the arrows cannot leave it.
- Elements with their own tabIndex={-1} are left alone, and a nested composite widget (a RadioGroup, a tab list, โ€ฆ; not Toolbar.RadioGroup) counts as one control that keeps its own Tab stop and arrow keys.
- A Menu or Popover opened from a control keeps its own keys: arrows, Home and End pressed in the popup never move focus back to the toolbar's controls.
- A consumer onKeyDown runs first; event.preventDefault() in it cancels the navigation.
- Renders data-size and data-orientation.

React Server Components cannot dot into a client module: import the flat names ToolbarButton, ToolbarToggleButton, ToolbarRadioGroup, ToolbarRadioButton, ToolbarGroup and ToolbarDivider there; Toolbar.Button etc. work in client files.

Examples

Default

export const Default: Story = {};

Vertical

export const Vertical: Story = {
  args: {
    orientation: 'vertical',
  },
};

Text Editor

export const TextEditor: Story = {
  args: {
    'aria-label': 'Text formatting',
    defaultCheckedValues: { format: ['bold'], align: ['left'] },
    children: (
      <>
        <Toolbar.ToggleButton
          name="format"
          value="bold"
          icon={<BoldIcon />}
          aria-label="Bold"
          isAccessible
        />
        <Toolbar.ToggleButton
          name="format"
          value="italic"
          icon={<ItalicIcon />}
          aria-label="Italic"
          isAccessible
        />
        <Toolbar.ToggleButton
          name="format"
          value="underline"
          icon={<UnderlineIcon />}
          aria-label="Underline"
          isAccessible
        />
        <Toolbar.Divider />
        <Toolbar.RadioGroup aria-label="Text alignment">
          <Toolbar.RadioButton
            name="align"
            value="left"
            icon={<AlignLeftIcon />}
            aria-label="Align left"
            isAccessible
          />
          <Toolbar.RadioButton
            name="align"
            value="center"
            icon={<AlignCenterIcon />}
            aria-label="Align center"
            isAccessible
          />
          <Toolbar.RadioButton
            name="align"
            value="right"
            icon={<AlignRightIcon />}
            aria-label="Align right"
            isAccessible
          />
        </Toolbar.RadioGroup>
        <Toolbar.Divider />
        <Toolbar.Group aria-label="Document">
          <Toolbar.Button appearance="primary">Share</Toolbar.Button>
        </Toolbar.Group>
      </>
    ),
  },
};

Sizes

export const Sizes: Story = {
  argTypes: {
    size: { control: false },
  },
  render: (args) => (
    <div className="flex flex-col items-start gap-3">
      {sizes.map((size) => (
        <Toolbar {...args} key={size} size={size} aria-label={`Formatting (${size})`}>
          <Toolbar.ToggleButton name="format" value="bold">
            Bold
          </Toolbar.ToggleButton>
          <Toolbar.Divider />
          <Toolbar.RadioGroup aria-label={`Text alignment (${size})`}>
            <Toolbar.RadioButton name="align" value="left">
              Left
            </Toolbar.RadioButton>
            <Toolbar.RadioButton name="align" value="right">
              Right
            </Toolbar.RadioButton>
          </Toolbar.RadioGroup>
          <Toolbar.Divider />
          <Toolbar.Button>{size}</Toolbar.Button>
          <Button appearance="subtle">Help</Button>
        </Toolbar>
      ))}
    </div>
  ),
};

Vertical Buttons

export const VerticalButtons: Story = {
  args: {
    'aria-label': 'Clipboard',
    children: (
      <>
        <Toolbar.Button vertical icon={<PasteIcon />}>
          Paste
        </Toolbar.Button>
        <Toolbar.Button vertical icon={<CutIcon />}>
          Cut
        </Toolbar.Button>
        <Toolbar.Button vertical icon={<CopyIcon />}>
          Copy
        </Toolbar.Button>
      </>
    ),
  },
};

Controlled Checked Values

Format: none; alignment: left
export const ControlledCheckedValues: Story = {
  render: function ControlledStory(args) {
    const [values, setValues] = useState<CheckedValues>({ format: [], align: ['left'] });
    return (
      <div className="flex flex-col items-start gap-2">
        <Toolbar
          {...args}
          checkedValues={values}
          onCheckedValuesChange={(next, details) => {
            setValues(next);
            args.onCheckedValuesChange?.(next, details);
          }}
        >
          <Toolbar.ToggleButton name="format" value="bold">
            Bold
          </Toolbar.ToggleButton>
          <Toolbar.ToggleButton name="format" value="italic">
            Italic
          </Toolbar.ToggleButton>
          <Toolbar.Divider />
          <Toolbar.RadioGroup aria-label="Text alignment">
            <Toolbar.RadioButton name="align" value="left">
              Left
            </Toolbar.RadioButton>
            <Toolbar.RadioButton name="align" value="center">
              Center
            </Toolbar.RadioButton>
          </Toolbar.RadioGroup>
        </Toolbar>
        <Text>
          Format: {values.format?.join(', ') || 'none'}; alignment: {values.align?.[0] ?? 'none'}
        </Text>
      </div>
    );
  },
};

With Disabled Control

export const WithDisabledControl: Story = {
  args: {
    'aria-label': 'Document actions',
    children: (
      <>
        <Toolbar.Button>Copy</Toolbar.Button>
        <Toolbar.Button disabledFocusable>Paste</Toolbar.Button>
        <Toolbar.Button disabled>Cut</Toolbar.Button>
        <Toolbar.Button>Delete</Toolbar.Button>
      </>
    ),
  },
};

Mixed Controls

export const MixedControls: Story = {
  args: {
    'aria-label': 'Search tools',
    children: (
      <>
        <ToggleButton appearance="subtle" size="small">
          Filter
        </ToggleButton>
        <input
          aria-label="Search"
          className="h-6 rounded border border-wave-input bg-wave-background px-2 text-wave-caption-1 text-wave-foreground"
        />
        <Link href="#toolbar-help">Help</Link>
      </>
    ),
  },
};

Props

NameTypeRequiredDefaultDescription
orientation'horizontal' | 'vertical'No'horizontal'

Layout and arrow-key axis: Left/Right move between items when horizontal (mirrored in RTL), Up/Down when vertical. Exposed as aria-orientation and data-orientation.

size'extra-small' | 'small' | 'medium' | 'large' | 'extra-large'No'medium'

Default size of Toolbar.Button, Toolbar.ToggleButton and Toolbar.RadioButton (their own size wins), and the toolbar's padding. Plain Buttons inside keep their own default. Exposed as data-size.

checkedValuesCheckedValuesNo

Pressed Toolbar.ToggleButtons and checked Toolbar.RadioButtons, per group name (controlled): { format: ['bold'], align: ['center'] }.

defaultCheckedValuesCheckedValuesNo{}

Initial checked values for uncontrolled usage.

onCheckedValuesChangeCheckedValuesChangeHandlerNo

Called when a toggle or radio changes them (only on change): the new checked values first, then details with the group's name, its checkedItems and the event (Fluent's onCheckedValueChange(event, { name, checkedItems }); WaveUI always passes details).

asReact.ElementTypeNo'div'

Render as a different element or component (its props are type-checked).

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • Toolbar.Button
  • Toolbar.ToggleButton
  • Toolbar.RadioGroup
  • Toolbar.RadioButton
  • Toolbar.Group
  • Toolbar.Divider

Stable class names

PartClass
rootwave-toolbar