Fragiola

API: components

Toolbar

A set of controls that is one tab stop, the arrows moving between them, nested ToggleGroups included (the APG toolbar), in each framework.

A container for a set of controls that is one tab stop, with the arrow keys moving between them (WAI-ARIA APG toolbar pattern): buttons, links, a text input, and Toggles and ToggleGroups, whose toggles become the toolbar's own items.

Text-format toolbar
Gallery

Behaviour

  • One tab stop: exactly one item has tabindex="0": the first one that can take focus, then the one that last had focus. Tab enters the toolbar there and leaves it at once.
  • Arrows: ArrowRight and ArrowLeft in a horizontal toolbar (mirrored in RTL), ArrowDown and ArrowUp in a vertical one, Home and End, through every item in document order, wrapping with loopFocus. The other orientation's arrows are left to the controls.
  • Nested composites: a ToggleGroup inside a Toolbar opens no focus of its own; its toggles register with the toolbar, which stays one tab stop. A Toggle placed directly in the toolbar is an item too. A Toolbar.Group only groups its items (and disables them with disabled).
  • Disabled items: a disabled Button or Input is skipped by the arrows (the APG's "typically not focusable"); with focusableWhenDisabled it is aria-disabled and reachable, and ignores presses (an Input is also readonly).
  • Text input: a Toolbar.Input keeps its caret keys: the arrows move the focus out only when the caret is at the text's edge in their direction and nothing is selected, Home and End only when it is empty. The toolbar's keys select its whole text when they move the focus to it.
  • Name: the toolbar is a role="toolbar"; name it with aria-label or aria-labelledby.

Anatomy

partelementdata-primitives-partrole
Rootdivtoolbar-rootthe toolbar; holds the roving tab stop
Buttonbuttontoolbar-buttonan item, with Button's behaviour
Linkatoolbar-linkan item
Inputinputtoolbar-inputan item that keeps its caret keys
Groupdivtoolbar-groupa group of items
Separatordivtoolbar-separatora separator across the toolbar

Usage

import { Toggle } from "@fragiola/primitives-react/toggle";
import { ToggleGroup } from "@fragiola/primitives-react/toggle-group";
import { Toolbar } from "@fragiola/primitives-react/toolbar";

<Toolbar.Root aria-label="Formatting">
    <ToggleGroup aria-label="Text style" multiple>
        <Toggle value="bold">Bold</Toggle>
        <Toggle value="italic">Italic</Toggle>
    </ToggleGroup>
    <Toolbar.Separator />
    <Toolbar.Group aria-label="History">
        <Toolbar.Button onClick={undo}>Undo</Toolbar.Button>
        <Toolbar.Button disabled>Redo</Toolbar.Button>
    </Toolbar.Group>
    <Toolbar.Link href="/help">Help</Toolbar.Link>
    <Toolbar.Input aria-label="Search" />
</Toolbar.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue and Angular take the click, pointer, key and focus listeners as native events (@click, (click)).

Root

proptypedefaultdescription
orientation"horizontal" | "vertical""horizontal"which arrow keys move between the items
loopFocusbooleantruewhether the arrow keys wrap around
disabledbooleanfalseevery Button, Input, Toggle and ToggleGroup in it is disabled

Button

proptypedefaultdescription
disabledbooleanfalseignores presses and keys; skipped by the arrows unless focusableWhenDisabled
focusableWhenDisabledbooleanfalsea disabled button the arrows still reach (aria-disabled)
nativeButtonbooleantruewhether the rendered element is a native <button>
type"button" | "submit" | "reset""button" (native)forwarded
onClick (react)MouseEventHandlera click; not while disabled
onMouseDown (react)MouseEventHandlernot while disabled
onPointerDown (react)PointerEventHandlernot while disabled
onKeyDown (react)KeyboardEventHandlerruns before the non-native keys and the toolbar's; not while disabled
onKeyUp (react)KeyboardEventHandlernot while disabled
onFocus (react)FocusEventHandlerafter the toolbar took note of the focus

No props of its own (href and every attribute are forwarded).

Input

proptypedefaultdescription
disabledbooleanfalsethe input is disabled; skipped by the arrows unless focusableWhenDisabled
focusableWhenDisabledbooleanfalsea disabled input the arrows still reach: aria-disabled and readonly

Group

proptypedefaultdescription
disabledbooleanfalseevery item in it is disabled

Separator

No props of its own: it runs across the toolbar's orientation.

State and part attributes

partattributes
Rootrole="toolbar", aria-orientation, data-orientation, data-disabled
ButtonButton's (type="button", disabled or aria-disabled="true"), the roving tabindex, data-orientation, data-disabled
Linkthe roving tabindex, data-orientation
Inputthe roving tabindex, data-orientation, data-disabled; disabled, or aria-disabled="true" and readonly with focusableWhenDisabled
Grouprole="group", data-orientation, data-disabled
Separatorrole="separator", aria-orientation and data-orientation across the toolbar's

Keyboard

keyhorizontalvertical
Tab, Shift+Tabinto and out of the toolbar (one tab stop)the same
next itemArrowRight (ArrowLeft in RTL)ArrowDown
previous itemArrowLeft (ArrowRight in RTL)ArrowUp
Home, Endthe first, the last item that can take focusthe same
Enter, Spacethe item's own (a click, a link, a toggle)the same

In a Toolbar.Input, the arrows, Home and End move the caret first ("Behaviour").

Exports

entryexports
@fragiola/primitives-react/toolbarRenderProp, RovingOrientation, Toolbar, ToolbarButtonProps, ToolbarGroupProps, ToolbarInputProps, ToolbarItemState, ToolbarLinkProps, ToolbarLinkState, ToolbarRootProps, ToolbarRootState, ToolbarSeparatorProps, ToolbarSeparatorState
@fragiola/primitives-vue/toolbarRenderSlotProps, RovingOrientation, Toolbar, ToolbarButtonProps, ToolbarGroupProps, ToolbarInputProps, ToolbarItemState, ToolbarLinkState, ToolbarRootProps, ToolbarRootState, ToolbarSeparatorState
@fragiola/primitives-angular/toolbarRovingOrientation, ToolbarButton, ToolbarGroup, ToolbarInput, ToolbarItemState, ToolbarLink, ToolbarRoot, ToolbarRootState, ToolbarSeparator, ToolbarSeparatorState