Toolbar
A toolbar with keyboard navigation built on Base UI
Installation
bunx @prototyperco/cli add toolbarpnpm dlx shadcn@latest add https://prototyper-ui.com/r/toolbar.jsonnpx shadcn@latest add https://prototyper-ui.com/r/toolbar.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/toolbar.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/toolbar.jsonThis will add the following files to your project:
components/ui/toolbar.tsx
Usage
import {
Toolbar,
ToolbarButton,
ToolbarSeparator,
} from "@/components/ui/toolbar";
<Toolbar>
<ToolbarButton>Bold</ToolbarButton>
<ToolbarButton>Italic</ToolbarButton>
<ToolbarSeparator />
<ToolbarButton>Link</ToolbarButton>
</Toolbar>;Anatomy
<Toolbar>
<ToolbarGroup>
<ToolbarButton />
<ToolbarButton />
</ToolbarGroup>
<ToolbarSeparator />
<ToolbarGroup>
<ToolbarLink />
</ToolbarGroup>
<ToolbarInput />
</Toolbar>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Toolbar | toolbar | Root container with keyboard navigation | Yes |
ToolbarButton | toolbar-button | A button within the toolbar | No |
ToolbarLink | toolbar-link | A link within the toolbar | No |
ToolbarGroup | toolbar-group | Groups related toolbar items together | No |
ToolbarSeparator | toolbar-separator | Visual separator between toolbar items | No |
ToolbarInput | toolbar-input | A text input within the toolbar | No |
Examples
Vertical
Styling
Data Slots
Use data-slot attributes to target specific parts of the toolbar:
| Slot name | Element |
|---|---|
toolbar | Root toolbar container |
toolbar-button | Button element within the toolbar |
toolbar-link | Link element within the toolbar |
toolbar-group | Group wrapper for related items |
toolbar-separator | Separator line between items |
toolbar-input | Text input within the toolbar |
Customization Examples
/* Add a border around the toolbar */
[data-slot="toolbar"] {
@apply rounded-lg border bg-background p-1;
}
/* Style toolbar buttons with more padding */
[data-slot="toolbar-button"] {
@apply px-4;
}{
/* Override styles via className */
}
<Toolbar className="rounded-lg border bg-background p-1">
<ToolbarButton className="px-4">Bold</ToolbarButton>
</Toolbar>;API Reference
Toolbar
Root container that provides keyboard navigation between toolbar items.
Prop
Type
All Base UI Toolbar.Root props are forwarded via ...props.
ToolbarButton
A button within the toolbar that participates in keyboard navigation.
Prop
Type
All Base UI Toolbar.Button props are forwarded via ...props.
ToolbarLink
A link within the toolbar that participates in keyboard navigation.
Prop
Type
All Base UI Toolbar.Link props are forwarded via ...props.
ToolbarGroup
Groups related toolbar items together visually and semantically.
Prop
Type
All Base UI Toolbar.Group props are forwarded via ...props.
ToolbarSeparator
A visual separator between toolbar items or groups.
Prop
Type
All Base UI Toolbar.Separator props are forwarded via ...props.
ToolbarInput
A text input within the toolbar that participates in keyboard navigation.
Prop
Type
All Base UI Toolbar.Input props are forwarded via ...props.
Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Tab | Moves focus into the toolbar (focuses the first/last active item) |
ArrowRight | Moves focus to the next toolbar item (horizontal orientation) |
ArrowLeft | Moves focus to the previous toolbar item (horizontal orientation) |
ArrowDown | Moves focus to the next toolbar item (vertical orientation) |
ArrowUp | Moves focus to the previous toolbar item (vertical orientation) |
Home | Moves focus to the first toolbar item |
End | Moves focus to the last toolbar item |
Space / Enter | Activates the focused toolbar button or link |
ARIA Attributes
Toolbarrenders withrole="toolbar"by default via Base UI.aria-orientationis set to match theorientationprop.aria-disabledis set on the toolbar whendisabledistrue.- Toolbar items are part of a single tab stop; arrow keys navigate between items within the toolbar.
- Focus management follows the roving tabindex pattern so only one item is tabbable at a time.