@k8ordo/ui

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

ts
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.

tsx
<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

tsx
<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: -
PropTypeDefault
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: -
PropTypeDefault
renderItem(props: ToolbarItemProps) => ReactElement-
k8ordo

React libraries that use Baseline features without holding back.