Toolbar
A container for grouping a set of buttons and controls.
View as MarkdownUsage guidelines
To ensure that toolbars are accessible and helpful, follow these guidelines:
- Use inputs sparingly: Left and right arrow keys are used to both move the text insertion cursor in an input, and to navigate among controls in horizontal toolbars. When using an input in a horizontal toolbar, use only one and place it as the last element of the toolbar.
Anatomy
Import the component and assemble its parts:
import { Toolbar } from '@base-ui/react/toolbar';
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
<Toolbar.Group />
<Toolbar.Input />
</Toolbar.Root>Examples
Using with Menu
All Base UI popup components that provide a Trigger component can be integrated with a toolbar by passing the trigger to <Toolbar.Button> with the render prop:
return (
<Toolbar.Root>
<Menu.Root>
<Toolbar.Button render={<Menu.Trigger />} />
<Menu.Portal>
{/* Compose the rest of the menu */}
</Menu.Portal>
</Menu.Root>
</Toolbar.Root>
)This applies to <AlertDialog>, <Dialog>, <Menu>, <Popover>, and <Select>.
Using with Tooltip
Unlike other popups, the toolbar item should be passed to the render prop of <Tooltip.Trigger>:
return (
<Toolbar.Root>
<Tooltip.Root>
<Tooltip.Trigger render={<Toolbar.Button />} />
<Tooltip.Portal>
{/* Compose the rest of the tooltip */}
</Tooltip.Portal>
</Tooltip.Root>
</Toolbar.Root>
)Using with NumberField
To use a NumberField in the toolbar, pass <NumberField.Input> to <Toolbar.Input> using the render prop:
return (
<Toolbar.Root>
<NumberField.Root>
<NumberField.Group>
<NumberField.Decrement />
<Toolbar.Input render={<NumberField.Input />} />
<NumberField.Increment />
</NumberField.Group>
</NumberField.Root>
</Toolbar.Root>
)API reference
Root
A container for grouping a set of controls, such as buttons, toggle groups, or menus.
Renders a <div> element.
loopFocusbooleantrue
boolean- Name
- Description
If
true, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached.- Type
boolean | undefined- Default
true
disabledboolean—
boolean- Name
- Type
boolean | undefined
orientationToolbar.Root.Orientation'horizontal'
Toolbar.Root.Orientation- Name
- Description
The orientation of the toolbar.
- Type
Toolbar.Root.Orientation | undefined- Default
'horizontal'
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Root.State, ) => ReactElement) | undefined
data-orientation
data-disabled
Additional Types
Toolbar.Root.Props
Re-Export of Root props as ToolbarRootProps
Toolbar.Root.State
type ToolbarRootState = { disabled: boolean; orientation: Toolbar.Root.Orientation };Toolbar.Root.Orientation
type ToolbarRootOrientation = 'horizontal' | 'vertical';Toolbar.Root.ItemMetadata
type ToolbarRootItemMetadata = { focusableWhenDisabled: boolean };Button
A button that can be used as-is or as a trigger for other components.
Renders a <button> element.
focusableWhenDisabledbooleantrue
boolean- Description
When
truethe item remains focuseable when disabled.- Type
boolean | undefined- Default
true
nativeButtonbooleantrue
boolean- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
boolean | undefined- Default
true
disabledbooleanfalse
boolean- Name
- Description
When
truethe item is disabled.- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Button.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Button.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Button.State, ) => ReactElement) | undefined
data-orientation
data-disabled
data-focusable
Additional Types
Toolbar.Button.Props
Re-Export of Button props as ToolbarButtonProps
Toolbar.Button.State
type ToolbarButtonState = {
disabled: boolean;
focusable: boolean;
orientation: Toolbar.Root.Orientation;
};Link
A link component.
Renders an <a> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Link.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Link.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Link.State, ) => ReactElement) | undefined
data-orientation
Additional Types
Toolbar.Link.Props
Re-Export of Link props as ToolbarLinkProps
Toolbar.Link.State
type ToolbarLinkState = { orientation: Toolbar.Root.Orientation };Input
A native input element that integrates with Toolbar keyboard navigation.
Renders an <input> element.
defaultValueUnion—
Union- Name
- Type
string | number | string[] | undefined
focusableWhenDisabledbooleantrue
boolean- Description
When
truethe item remains focuseable when disabled.- Type
boolean | undefined- Default
true
disabledbooleanfalse
boolean- Name
- Description
When
truethe item is disabled.- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Input.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Input.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Input.State, ) => ReactElement) | undefined
data-orientation
data-disabled
data-focusable
Additional Types
Toolbar.Input.Props
Re-Export of Input props as ToolbarInputProps
Toolbar.Input.State
type ToolbarInputState = {
disabled: boolean;
focusable: boolean;
orientation: Toolbar.Root.Orientation;
};Group
Groups several toolbar items or toggles.
Renders a <div> element.
disabledbooleanfalse
boolean- Name
- Description
When
trueall toolbar items in the group are disabled.- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Root.State, ) => ReactElement) | undefined
data-orientation
data-disabled
Additional Types
Toolbar.Group.Props
Re-Export of Group props as ToolbarGroupProps
Separator
A separator element accessible to screen readers.
Renders a <div> element.
orientationToolbar.Root.Orientation—
Toolbar.Root.Orientation- Name
- Type
Toolbar.Root.Orientation | undefined
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Toolbar.Separator.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Toolbar.Separator.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Toolbar.Separator.State, ) => ReactElement) | undefined
data-orientation
Additional Types
Toolbar.Separator.Props
Re-Export of Separator props as ToolbarSeparatorProps
Toolbar.Separator.State
type ToolbarSeparatorState = { orientation: Toolbar.Root.Orientation };