component
Toolbar
A row of IconButtons that act on one thing, on a raised strip, with thin lines between the groups. The arrow keys move between them.
Defaultimport { Toolbar, ToolbarSeparator } from 'rost/components/toolbar/Toolbar'
<Toolbar label="Preview">
<IconButton variant="tertiary" aria-label="Back" icon={<Icon name="arrow-left" size="small" />} onClick={back} />
<IconButton variant="tertiary" aria-label="Forward" icon={<Icon name="arrow-right" size="small" />} onClick={forward} />
<ToolbarSeparator />
<IconButton variant="tertiary" aria-label="Desktop" icon={<Icon name="desktop" size="small" />} onClick={() => setView('desktop')} />
<IconButton variant="tertiary" aria-label="Phone" icon={<Icon name="mobile" size="small" />} onClick={() => setView('phone')} />
</Toolbar> src/components/toolbar/Toolbar.tsx
import { useEffect, useRef, type HTMLAttributes, type KeyboardEvent, type ReactNode } from 'react'
import './toolbar.css'
export interface ToolbarProps extends HTMLAttributes<HTMLDivElement> {
/** What the tools act on, for screen readers. */
readonly label: string
/** Tertiary IconButtons, with a ToolbarSeparator between groups. */
readonly children: ReactNode
}
const b = 'rost-toolbar'
const buttons = (root: HTMLElement) => Array.from(root.querySelectorAll<HTMLElement>('button:not(:disabled), a[href]'))
/**
* A row of IconButtons that act on one thing. One button is in the tab order;
* the arrow keys move between them. Built from contracts/toolbar.contract.yaml.
*/
export function Toolbar({ label, children, className, onKeyDown, onFocus, ...rest }: ToolbarProps) {
const ref = useRef<HTMLDivElement>(null)
const roam = (to: HTMLElement) => { for (const el of buttons(ref.current!)) el.tabIndex = el === to ? 0 : -1 }
useEffect(() => {
const all = ref.current ? buttons(ref.current) : []
if (all.length && !all.some((el) => el.getAttribute('tabindex') === '0')) roam(all[0])
})
const key = (e: KeyboardEvent<HTMLDivElement>) => {
onKeyDown?.(e)
const all = buttons(ref.current!)
const at = all.indexOf(document.activeElement as HTMLElement)
if (at < 0) return
const to = { ArrowRight: at + 1, ArrowLeft: at - 1, Home: 0, End: all.length - 1 }[e.key]
if (to === undefined) return
e.preventDefault()
const next = all[(to + all.length) % all.length]
roam(next)
next.focus()
}
return (
<div
ref={ref}
role="toolbar"
aria-label={label}
className={[b, className].filter(Boolean).join(' ')}
onKeyDown={key}
onFocus={(e) => { onFocus?.(e); if (e.target !== ref.current && buttons(ref.current!).includes(e.target as HTMLElement)) roam(e.target as HTMLElement) }}
{...rest}
>
{children}
</div>
)
}
/** A thin upright line between two groups of buttons. */
export function ToolbarSeparator() {
return <span className={`${b}__separator`} role="separator" aria-orientation="vertical" />
}
The source for everything on this page: contracts/toolbar.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: toolbar
name: Toolbar
kind: component
status: review
summary: "A row of IconButtons that act on one thing, on a raised strip, with thin lines between the groups. The arrow keys move between them."
category: actions
related: [ icon-button, toggle-group, menu ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "746:135"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=746-135
extractedAt: "2026-11-17"
extractedBy: hand
frozenAt: "2026-11-17"
props:
children: { type: slot, required: true, notes: "Tertiary IconButtons, with a `ToolbarSeparator` between groups." }
label: { type: string, required: true, notes: "What the tools act on, for screen readers: Preview, Invoice." }
elements:
root:
notes: "A row, 4px between the buttons and 4px around them, on the secondary surface with an edge and 12px corners."
styles:
display: { value: inline-flex, assert: false }
align-items: { value: center }
gap: { token: spacing/gap/2xsmall, value: 4px }
padding: { token: spacing/gap/2xsmall, value: 4px }
border-radius: { token: spacing/radius/medium, value: 12px }
background: { token: toolbar/background, value: "#171717" }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside." }
outline-color: { token: toolbar/edge, value: "#3a3a3a" }
separator:
notes: "A 1px line, 24px tall, between two groups of buttons."
styles:
display: { value: block, assert: false }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/outline/small, value: 1px }
height: { token: spacing/size/small, value: 24px }
background: { token: toolbar/separator, value: "#3a3a3a" }
guidance:
status: proposed
use:
- title: Tools for one thing
text: "Over a preview, an editor or a document: back and forward, desktop or phone, zoom."
avoid:
- title: The page's main action
text: "Save or Send is a **Button** with words, not an icon in a strip."
- title: Picking one of a few views
text: "When exactly one is on, that's a **ToggleGroup**."
behaviour: "Tab lands on one button and leaves the Toolbar on the next press. Left and right move between the buttons, Home and End jump to the ends. Each button does its own thing."
accessibility:
element: "`role=\"toolbar\"` with an `aria-label`. Only one button is in the tab order at a time. The separators are `role=\"separator\"`, upright."
name: "The `label` prop. Each IconButton has its own."
colour: "The edge is drawing, not information. The icons are the IconButtons' own."
Install
npx github:Runceanu/rost add toolbar It lands in src/rost/toolbar/, with what it needs and its contract. Install has the rest.
When to use
Tools for one thing
Over a preview, an editor or a document: back and forward, desktop or phone, zoom.
When not to use
The page's main action
Save or Send is a Button with words, not an icon in a strip.
Picking one of a few views
When exactly one is on, that's a ToggleGroup.
Behaviour
Tab lands on one button and leaves the Toolbar on the next press. Left and right move between the buttons, Home and End jump to the ends. Each button does its own thing.
Accessibility
- Element
role="toolbar"with anaria-label. Only one button is in the tab order at a time. The separators arerole="separator", upright. - Name
The
labelprop. Each IconButton has its own. - Colour
The edge is drawing, not information. The icons are the IconButtons' own.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
children | slot | | |
label | string | | |
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap4pxspacing/gap/2xsmall -
padding4pxspacing/gap/2xsmall -
border-radius12pxspacing/radius/medium -
background#171717toolbar/background -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside. -
outline-color#3a3a3atoolbar/edge
displayinline-flex · align-itemscenter · outline-stylesolid
separator
-
width1pxspacing/outline/small -
height24pxspacing/size/small -
background#3a3a3atoolbar/separator
displayblock · flex-shrink0