Toolbar component for editor interfaces with support for action buttons, toggle buttons, logical groups, separators, and spacers. Works in both horizontal and vertical orientations. Implements roving tabindex for keyboard navigation.
Import
import { Toolbar } from ' entangle-ui ' ;
Usage
import { SaveIcon, UndoIcon, RedoIcon } from ' entangle-ui ' ;
< Toolbar aria-label = " Main toolbar " >
< Toolbar.Button icon = { < SaveIcon /> } tooltip = " Save " onClick = { handleSave } />
< Toolbar.Button icon = { < UndoIcon /> } tooltip = " Undo " onClick = { handleUndo } />
< Toolbar.Button icon = { < RedoIcon /> } tooltip = " Redo " onClick = { handleRedo } />
onPressedChange = { setGridVisible }
< Toolbar.Button onClick = { handleRender } variant = " filled " >
Compound Components
Component Purpose Toolbar.ButtonStandard action button with icon and/or text Toolbar.ToggleToggle button with pressed/unpressed state Toolbar.GroupLogical grouping of related buttons Toolbar.SeparatorVisual divider between groups Toolbar.SpacerFlexible spacer that pushes items apart
Orientation
The toolbar supports both horizontal (default) and vertical orientations. The keyboard navigation arrow keys adapt automatically.
/* Horizontal (default) */
< Toolbar orientation = " horizontal " aria-label = " Top toolbar " >
< Toolbar.Button icon = { < SelectIcon /> } tooltip = " Select " />
< Toolbar.Button icon = { < MoveIcon /> } tooltip = " Move " />
< Toolbar orientation = " vertical " aria-label = " Side toolbar " >
< Toolbar.Button icon = { < SelectIcon /> } tooltip = " Select " />
< Toolbar.Button icon = { < MoveIcon /> } tooltip = " Move " />
< Toolbar.Button icon = { < RotateIcon /> } tooltip = " Rotate " />
Sizes
The size prop controls the density of toolbar buttons.
< Toolbar size = " sm " aria-label = " Compact toolbar " >
< Toolbar.Button icon = { < SaveIcon /> } tooltip = " Save " />
< Toolbar size = " md " aria-label = " Standard toolbar " >
< Toolbar.Button icon = { < SaveIcon /> } tooltip = " Save " />
Size Use case smCompact toolbars, secondary panels mdStandard toolbars (default)
Toolbar buttons support three visual variants.
< Toolbar.Button variant = " default " icon = { < CopyIcon /> } tooltip = " Copy " />
< Toolbar.Button variant = " ghost " icon = { < SettingsIcon /> } tooltip = " Settings " />
< Toolbar.Button variant = " filled " onClick = { handlePlay } >
Variant Description defaultStandard button appearance (default) ghostMinimal button with no border filledSolid accent background for primary actions
Use Toolbar.Toggle for buttons that switch between pressed and unpressed states. The parent manages the state.
const [ wireframe , setWireframe ] = useState ( false );
const [ snap , setSnap ] = useState ( true );
onPressedChange = { setWireframe }
onPressedChange = { setSnap }
Groups and Separators
Use Toolbar.Group to logically group related buttons and Toolbar.Separator to add visual dividers. The separator orientation is automatically the opposite of the toolbar orientation (vertical separator in a horizontal toolbar).
< Toolbar.Group aria-label = " Transform tools " >
< Toolbar.Button icon = { < MoveIcon /> } tooltip = " Move " />
< Toolbar.Button icon = { < RotateIcon /> } tooltip = " Rotate " />
< Toolbar.Button icon = { < ScaleIcon /> } tooltip = " Scale " />
< Toolbar.Group aria-label = " View options " >
onPressedChange = { setOrtho }
Spacer
Toolbar.Spacer is a flexible element that fills available space, allowing you to push items to opposite ends of the toolbar.
< Toolbar.Button icon = { < MenuIcon /> } tooltip = " Menu " />
< Toolbar.Button icon = { < SettingsIcon /> } tooltip = " Settings " />
Props
Prop Type Default Description orientation 'horizontal' | 'vertical' 'horizontal' Layout orientation. Arrow key navigation adapts to match. size 'sm' | 'md' 'md' Size of toolbar items. children ReactNode — Toolbar sub-components (Button, Toggle, Group, Separator, Spacer). aria-label string — Accessible label for the toolbar. className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLDivElement> — Ref to the root element.
Prop Type Default Description icon ReactNode — Icon element to display. When provided, children text is visually hidden. children ReactNode — Label text. Hidden when an icon is provided. variant 'default' | 'ghost' | 'filled' 'default' Visual variant of the button. tooltip string — Tooltip text shown on hover (rendered as the native title attribute). onClick () => void — Click handler. disabled boolean false Whether the button is disabled. className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLButtonElement> — Ref to the button element.
Prop Type Default Description pressed * boolean — Whether the toggle is in the pressed state. onPressedChange * (pressed: boolean) => void — Called when the pressed state should change. icon ReactNode — Icon element to display. children ReactNode — Label text. tooltip string — Tooltip text shown on hover. disabled boolean false Whether the toggle is disabled. className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLButtonElement> — Ref to the button element.
Prop Type Default Description children ReactNode — Grouped toolbar items. aria-label string — Accessible label for the group. className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLDivElement> — Ref to the group element.
Prop Type Default Description className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLDivElement> — Ref to the separator element.
Prop Type Default Description className string — Additional CSS class names. style CSSProperties — Inline styles. testId string — Test identifier for automated testing. ref Ref<HTMLDivElement> — Ref to the spacer element.
Accessibility
The root element has role="toolbar" with aria-orientation set to match the orientation prop
Implements roving tabindex: only the toolbar container is in the tab order (tabIndex={0}), and arrow keys move focus between items
ArrowRight / ArrowDown moves focus to the next button (depending on orientation)
ArrowLeft / ArrowUp moves focus to the previous button
Home moves focus to the first button
End moves focus to the last button
When the toolbar receives focus, the first button is automatically focused
Toggle buttons use aria-pressed to communicate state
Groups use role="group" and support an aria-label
Separators use role="separator" with the appropriate aria-orientation