# Toolbar (/docs/toolbar)





## API Reference [#api-reference]

<BaseUIReference href="https://base-ui.com/react/components/toolbar" />

## Basic [#basic]

<Preview cssProperties="toolbarPlaygroundCssProperties">
  <ToolbarExample />

  <Preview.Code>
    {`
          import {
            BellIcon,
            Toolbar,
            ToolbarButton,
            ToolbarGroup,
            ToolbarInput,
            ToolbarLink,
            ToolbarSeparator,
          } from "moduix";

          export function ToolbarDemo() {
            return (
              <Toolbar aria-label="Document actions">
                <ToolbarGroup aria-label="History">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                </ToolbarGroup>
                <ToolbarSeparator />
                <ToolbarInput aria-label="Search actions" placeholder="Search actions" />
                <ToolbarButton aria-label="Notifications">
                  <BellIcon />
                </ToolbarButton>
                <ToolbarLink href="#">History</ToolbarLink>
              </Toolbar>
            );
          }
        `}
  </Preview.Code>

  <Preview.CSSProperties>
    {(context) => <ToolbarCssPropertiesPanel {...context} />}
  </Preview.CSSProperties>

  <Preview.CSSPlayground>
    {(context) => <ToolbarCssPlaygroundPanel {...context} />}
  </Preview.CSSPlayground>
</Preview>

## Anatomy [#anatomy]

`Toolbar` groups related controls into one keyboard navigation region. Use visible parts for
actions, grouped actions, separators, inputs, and links.

```text
Toolbar[aria-label]
├─ ToolbarGroup[aria-label]
│  └─ ToolbarButton
├─ ToolbarSeparator
├─ ToolbarInput
├─ ToolbarButton
└─ ToolbarLink
```

```tsx
<Toolbar aria-label="Document actions">
  <ToolbarGroup aria-label="History">
    <ToolbarButton>Undo</ToolbarButton>
    <ToolbarButton>Redo</ToolbarButton>
  </ToolbarGroup>
  <ToolbarSeparator />
  <ToolbarInput aria-label="Search actions" placeholder="Search actions" />
  <ToolbarButton aria-label="Notifications">
    <BellIcon />
  </ToolbarButton>
  <ToolbarLink href="#">History</ToolbarLink>
</Toolbar>
```

| Part               | Role                                                                                              |
| ------------------ | ------------------------------------------------------------------------------------------------- |
| `Toolbar`          | Root toolbar region. Controls orientation, disabled state, visual `variant`, and control `size`.  |
| `ToolbarGroup`     | Groups related controls inside the toolbar and gives them a shared label when needed.             |
| `ToolbarButton`    | Toolbar-aware button. Compose it with `Toggle`, `SelectTrigger`, or another trigger via `render`. |
| `ToolbarInput`     | Native input that participates in toolbar keyboard navigation.                                    |
| `ToolbarLink`      | Toolbar-aware anchor for related navigation or metadata links.                                    |
| `ToolbarSeparator` | Visual separator. By default it uses the opposite orientation of the root toolbar.                |

`Toolbar` does not use portal-like service layers such as `portal`, `positioner`, `backdrop`,
or `viewport`. All exported parts are visible composition slots, so style the root and parts
directly with `className` or scoped CSS variables.

## Composition [#composition]

Use `Toolbar` for shared behavior and layout props: `aria-label`, `orientation`, `disabled`,
`variant`, and `size`. Use `ToolbarGroup` when a subset of controls needs its own accessible
name, and use `ToolbarSeparator` to divide unrelated groups.

`ToolbarButton` supports the Base UI `render` prop. This lets one element act as both a toolbar
item and another interactive primitive, such as a `Toggle` or `SelectTrigger`, without nesting
interactive elements.

```tsx
<Toolbar aria-label="Text properties">
  <Select defaultValue="Inter">
    <ToolbarButton render={<SelectTrigger />} aria-label="Font family">
      <SelectValue />
      <SelectIcon>
        <ChevronUpDownIcon />
      </SelectIcon>
    </ToolbarButton>
    <SelectContent>
      <SelectList>
        {fonts.map((font) => (
          <SelectItem key={font} value={font}>
            <SelectItemIndicator />
            <SelectItemText>{font}</SelectItemText>
          </SelectItem>
        ))}
      </SelectList>
    </SelectContent>
  </Select>
</Toolbar>
```

Popup primitives rendered from toolbar buttons, such as `SelectContent`, own their internal
portal and positioner behavior. Configure those slots on that popup component, not on `Toolbar`.

## Examples [#examples]

### Toggle Group [#toggle-group]

Compose `ToolbarButton` with `Toggle` inside a `ToggleGroup` when toolbar items need pressed state.

<Preview>
  <ToolbarToggleGroupExample />

  <Preview.Code>
    {`
          import {
            BellIcon,
            StarIcon,
            Toggle,
            ToggleGroup,
            Toolbar,
            ToolbarButton,
            ToolbarGroup,
            ToolbarSeparator,
          } from "moduix";

          export function ToolbarToggleGroupDemo() {
            return (
              <Toolbar aria-label="Editor formatting">
                <ToggleGroup multiple defaultValue={["bold"]} aria-label="Text formatting" variant="ghost">
                  <ToolbarButton render={<Toggle />} value="bold" aria-label="Bold">
                    <strong>B</strong>
                  </ToolbarButton>
                  <ToolbarButton render={<Toggle />} value="italic" aria-label="Italic">
                    <em>I</em>
                  </ToolbarButton>
                  <ToolbarButton render={<Toggle />} value="underline" aria-label="Underline">
                    <u>U</u>
                  </ToolbarButton>
                </ToggleGroup>

                <ToolbarSeparator />

                <ToolbarGroup aria-label="Insert">
                  <ToolbarButton aria-label="Add favorite">
                    <StarIcon />
                  </ToolbarButton>
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </ToolbarGroup>
              </Toolbar>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Select And Input [#select-and-input]

Use the `render` prop to turn toolbar buttons into popup triggers, and keep inputs limited in horizontal toolbars.

<Preview>
  <ToolbarSelectInputExample />

  <Preview.Code>
    {`
          import {
            ChevronUpDownIcon,
            Select,
            SelectContent,
            SelectIcon,
            SelectItem,
            SelectItemIndicator,
            SelectItemText,
            SelectList,
            SelectTrigger,
            SelectValue,
            Toolbar,
            ToolbarButton,
            ToolbarInput,
            ToolbarLink,
            ToolbarSeparator,
          } from "moduix";

          export function ToolbarSelectInputDemo() {
            return (
              <Toolbar aria-label="Text properties">
                <Select defaultValue="Inter">
                  <ToolbarButton render={<SelectTrigger />} aria-label="Font family">
                    <SelectValue />
                    <SelectIcon>
                      <ChevronUpDownIcon />
                    </SelectIcon>
                  </ToolbarButton>
                  <SelectContent>
                    <SelectList>
                      {fonts.map((font) => (
                        <SelectItem key={font} value={font}>
                          <SelectItemIndicator />
                          <SelectItemText>{font}</SelectItemText>
                        </SelectItem>
                      ))}
                    </SelectList>
                  </SelectContent>
                </Select>

                <ToolbarSeparator />
                <ToolbarInput aria-label="Search actions" placeholder="Search actions" />
                <ToolbarLink href="#">History</ToolbarLink>
              </Toolbar>
            );
          }
        `}
  </Preview.Code>

  <Preview.Data>
    {`
          const fonts = ["Inter", "Arial", "Helvetica", "Georgia"];
        `}
  </Preview.Data>
</Preview>

### Variants [#variants]

Use `variant` to match the toolbar surface to the surrounding layout.

<Preview>
  <ToolbarVariantsExample />

  <Preview.Code>
    {`
          import { BellIcon, Toolbar, ToolbarButton, ToolbarSeparator } from "moduix";

          export function ToolbarVariantsDemo() {
            return (
              <>
                <Toolbar aria-label="Default toolbar">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
                <Toolbar aria-label="Outline toolbar" variant="outline">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
                <Toolbar aria-label="Ghost toolbar" variant="ghost">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
              </>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Sizes [#sizes]

Use `size` to align toolbar controls with compact or roomy interfaces.

<Preview>
  <ToolbarSizesExample />

  <Preview.Code>
    {`
          import { BellIcon, Toolbar, ToolbarButton, ToolbarSeparator } from "moduix";

          export function ToolbarSizesDemo() {
            return (
              <>
                <Toolbar aria-label="Small toolbar" size="sm">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
                <Toolbar aria-label="Medium toolbar" size="md">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
                <Toolbar aria-label="Large toolbar" size="lg">
                  <ToolbarButton>Undo</ToolbarButton>
                  <ToolbarButton>Redo</ToolbarButton>
                  <ToolbarSeparator />
                  <ToolbarButton aria-label="Notifications">
                    <BellIcon />
                  </ToolbarButton>
                </Toolbar>
              </>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Vertical [#vertical]

Set `orientation="vertical"` for toolbars that stack controls in a column.

<Preview>
  <ToolbarVerticalExample />

  <Preview.Code>
    {`
          import { StarIcon, Toolbar, ToolbarButton, ToolbarSeparator } from "moduix";

          export function ToolbarVerticalDemo() {
            return (
              <Toolbar orientation="vertical" aria-label="Vertical tools">
                <ToolbarButton>Move</ToolbarButton>
                <ToolbarButton>Scale</ToolbarButton>
                <ToolbarSeparator />
                <ToolbarButton aria-label="Favorite">
                  <StarIcon />
                </ToolbarButton>
              </Toolbar>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Disabled Controls [#disabled-controls]

Disable individual toolbar controls when an action is visible but unavailable.

<Preview>
  <ToolbarDisabledControlsExample />

  <Preview.Code>
    {`
          import {
            BellIcon,
            Toolbar,
            ToolbarButton,
            ToolbarInput,
            ToolbarSeparator,
          } from "moduix";

          export function ToolbarDisabledControlsDemo() {
            return (
              <Toolbar aria-label="Disabled document actions">
                <ToolbarButton>Undo</ToolbarButton>
                <ToolbarButton disabled>Redo</ToolbarButton>
                <ToolbarSeparator />
                <ToolbarInput aria-label="Search disabled actions" placeholder="Search actions" disabled />
                <ToolbarButton aria-label="Notifications" disabled>
                  <BellIcon />
                </ToolbarButton>
              </Toolbar>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Custom Icons [#custom-icons]

Pass icons as children. Icon-only buttons must include an accessible label.

<Preview>
  <ToolbarCustomIconsExample />

  <Preview.Code>
    {`
          import { Toolbar, ToolbarButton } from "moduix";

          export function ToolbarCustomIconsDemo() {
            return (
              <Toolbar aria-label="Text alignment">
                <ToolbarButton aria-label="Align left">
                  <AlignLeftIcon />
                </ToolbarButton>
                <ToolbarButton aria-label="Align center">
                  <AlignCenterIcon />
                </ToolbarButton>
                <ToolbarButton aria-label="Align right">
                  <AlignRightIcon />
                </ToolbarButton>
              </Toolbar>
            );
          }

          function AlignLeftIcon() {
            return (
              <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
                <path
                  d="M2.5 3.5h11M2.5 8h8M2.5 12.5h11"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                />
              </svg>
            );
          }

          function AlignCenterIcon() {
            return (
              <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
                <path
                  d="M2.5 3.5h11M4 8h8M2.5 12.5h11"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                />
              </svg>
            );
          }

          function AlignRightIcon() {
            return (
              <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false">
                <path
                  d="M2.5 3.5h11M5.5 8h8M2.5 12.5h11"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                />
              </svg>
            );
          }
        `}
  </Preview.Code>
</Preview>

### Class Names [#class-names]

Pass `className` to the root and each part when styling with CSS Modules, Tailwind CSS, or CSS-in-JS.

<Preview>
  <ToolbarClassNameExample />

  <Preview.Code>
    {`
          import {
            Toolbar,
            ToolbarButton,
            ToolbarInput,
            ToolbarSeparator,
          } from "moduix";

          export function ToolbarClassNamesDemo() {
            return (
              <Toolbar aria-label="Schedule controls" className={styles.customToolbar}>
                <ToolbarButton className={styles.customButton}>Day</ToolbarButton>
                <ToolbarButton className={styles.customButton}>Week</ToolbarButton>
                <ToolbarSeparator />
                <ToolbarInput
                  aria-label="Filter schedule"
                  placeholder="Filter"
                  className={styles.customInput}
                />
              </Toolbar>
            );
          }
        `}
  </Preview.Code>

  <Preview.CSS>
    {`
          .customToolbar {
            --toolbar-bg: color-mix(in oklab, var(--color-primary) 7%, transparent);
            --toolbar-border-color: color-mix(in oklab, var(--color-primary) 36%, var(--color-border));
            --toolbar-gap: var(--spacing-1);
            --toolbar-padding: var(--spacing-1);
            --toolbar-radius: var(--radius-md);
            --toolbar-control-bg-hover: color-mix(in oklab, var(--color-primary) 14%, transparent);
            --toolbar-control-bg-pressed: var(--color-primary);
            --toolbar-control-color-pressed: var(--color-primary-foreground);
            --toolbar-separator-color: color-mix(in oklab, var(--color-primary) 42%, var(--color-border));
          }

          .customButton {
            --toolbar-control-radius: var(--radius-sm);
            --toolbar-control-padding-x: var(--spacing-3);
          }

          .customInput {
            --toolbar-input-width: 8rem;
          }
        `}
  </Preview.CSS>
</Preview>
