Toolbar
An accessible role="toolbar" container with roving tabindex — the whole group is a single tab stop and arrow keys move focus between items (Home/End jump to the ends). Compose it from Toolbar.Button, Toolbar.Toggle, Toolbar.Link, and Toolbar.Separator.
Features
Example
Anatomy
import { Toolbar } from '@wire-ui/react'
<Toolbar.Root aria-label="Text formatting">
<Toolbar.Toggle aria-label="Bold"><b>B</b></Toolbar.Toggle>
<Toolbar.Toggle aria-label="Italic"><i>I</i></Toolbar.Toggle>
<Toolbar.Separator />
<Toolbar.Button aria-label="Align left">⬅</Toolbar.Button>
<Toolbar.Link href="#">Help</Toolbar.Link>
</Toolbar.Root>Styling
Toolbar.Toggle exposes data-state ("on" / "off") and aria-pressed for the pressed look. Toolbar.Root and Toolbar.Separator expose data-orientation. Each interactive item is wired into roving tabindex automatically.
<Toolbar.Toggle className="
text-black
data-[state=on]:bg-black data-[state=on]:text-white
">
<b>B</b>
</Toolbar.Toggle>
<Toolbar.Root className="
inline-flex gap-1
data-[orientation=vertical]:flex-col
" />Using data attributes
Toolbar.Root sets data-orientation. Toolbar.Toggle sets data-state. All interactive items carry data-toolbar-item. Toolbar.Separator sets data-orientation (perpendicular to the toolbar’s axis).
/* Pressed toggle */
[data-state="on"] { background: #000; color: #fff; }
/* Vertical toolbar */
[data-orientation="vertical"] { flex-direction: column; }Root props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | Layout + arrow-key axis |
loop | boolean | true | Wrap focus from last → first and vice versa |
Also accepts all native <div> attributes.
Button props
Toolbar.Button accepts all native <button> attributes. It is registered into the toolbar’s roving-focus group.
Toggle props
| Prop | Type | Default | Description |
|---|---|---|---|
pressed | boolean | — | Controlled pressed state |
defaultPressed | boolean | false | Initial pressed state (uncontrolled) |
onPressedChange | (pressed: boolean) => void | — | Called when the pressed state changes |
Also accepts all native <button> attributes (including disabled).
Link props
Toolbar.Link accepts all native <a> attributes (e.g. href). It is registered into the toolbar’s roving-focus group.
Separator props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | perpendicular to Root | Visual orientation; defaults to the axis perpendicular to the toolbar |
Also accepts all native <div> attributes.
Data attributes
| Attribute | Element | Values |
|---|---|---|
data-orientation | Root, Separator | "horizontal" / "vertical" |
data-state | Toggle | "on" / "off" |
data-toolbar-item | Button, Toggle, Link | Present on every roving-focus item |
Root sets role="toolbar" and aria-orientation. Separator sets role="separator" and aria-orientation. Toggle sets aria-pressed. Each item uses roving tabindex (tabIndex={0} for the active item, -1 for the rest).
Accessibility
- Implements the WAI-ARIA toolbar pattern with roving tabindex.
- The toolbar is a single tab stop; arrow keys move focus between items along the orientation axis.
- Disabled items (
disabledoraria-disabled="true") are skipped during arrow-key navigation. - Provide an
aria-label(oraria-labelledby) onToolbar.Rootto name the toolbar.
Keyboard Interactions
| Key | Description |
|---|---|
| ArrowRight / ArrowDown | Focus the next item (axis depends on orientation). |
| ArrowLeft / ArrowUp | Focus the previous item. |
| Home | Focus the first item. |
| End | Focus the last item. |
| Space / Enter | Activates a Button/Link or toggles a Toggle. |
| Tab | Moves focus into the toolbar (single tab stop), then out of it. |