Toolbar
A group of buttons that the arrow keys move between. Use it for a row of related actions, such as an editor’s formatting buttons.
Import
Copy code
import { Toolbar } from '@k8ordo/ui';Usage
It takes one Tab stop, and the arrow keys move inside it. Home and End jump to the ends, skipping disabled items. Returning focuses the item that was focused last. Each item is built in Toolbar.Item’s renderItem: spread the ref, tabIndex and onFocus it receives onto a Button or an IconButton.
Copy
Link
Bulleted list
Table
Copy code
<Toolbar.Root aria-label="Formatting">
<Toolbar.Item
renderItem={(props) => (
<IconButton {...props} label="Copy">
<CopyIcon size="sm" />
</IconButton>
)}
/>
<Toolbar.Item
renderItem={(props) => (
<IconButton
{...props}
aria-pressed={isList}
label="Bulleted list"
onClick={toggleList}
>
<ListIcon size="sm" />
</IconButton>
)}
/>
<Toolbar.Separator />
<Toolbar.Item
renderItem={(props) => (
<Button {...props} size="sm">
Save
</Button>
)}
/>
</Toolbar.Root>Toggles
Pass the pressed state as aria-pressed. A pressed item gets a darker background.
Vertical
Copy
Link
Bulleted list
Table
Copy code
<Toolbar.Root aria-label="Formatting" orientation="vertical">
{/* … */}
</Toolbar.Root>Props
Toolbar.Root
children?- Type:
ReactNode - Default: -
orientation?- Type:
'horizontal'|'vertical' - Default:
'horizontal' ref?- Type:
Ref<HTMLDivElement> - Default: -
| Prop | Type | Default |
|---|---|---|
children? | ReactNode | - |
orientation? | 'horizontal'|'vertical' | 'horizontal' |
ref? | Ref<HTMLDivElement> | - |
Inherited attributes (except the ones set internally): HTMLAttributes<HTMLDivElement>
Toolbar.Item
renderItem- Type:
(props: ToolbarItemProps) => ReactElement - Default: -
| Prop | Type | Default |
|---|---|---|
renderItem | (props: ToolbarItemProps) => ReactElement | - |