Toolbar
A container for grouping a set of buttons and controls.
View as MarkdownAccessibility 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-components/react/toolbar';
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
<Toolbar.Group />
<Toolbar.Input />
</Toolbar.Root>
API reference
Root
A container for grouping a set of controls, such as buttons, toggle groups, or menus.
Renders a <div>
element.
cols
number
(default: 1
)
number
1
- Name
- Description
The number of columns. When greater than 1, the toolbar is arranged into a grid.
- Type
number
- Default
1
disabled
boolean
boolean
- Name
- Type
boolean
loop
boolean
(default: true
)
boolean
true
- Name
- Description
If
true
, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached.- Type
boolean
- Default
true
orientation
Toolbar.Root.Orientation
(default: 'horizontal'
)
Toolbar.Root.Orientation
'horizontal'
- Name
- Description
The orientation of the toolbar.
- Type
Toolbar.Root.Orientation
- Default
'horizontal'
className
string | 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)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Toolbar.Root.State) => ReactElement)
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the toolbar is disabled.
Button
A button that can be used as-is or as a trigger for other components.
Renders a <button>
element.
focusableWhenDisabled
boolean
(default: true
)
boolean
true
- Description
When
true
the item remains focuseable when disabled.- Type
boolean
- Default
true
nativeButton
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the component renders a native
<button>
element when replacing it via therender
prop. Set tofalse
if the rendered element is not a button (e.g.<div>
).- Type
boolean
- Default
true
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
When
true
the item is disabled.- Type
boolean
- Default
false
className
string | 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)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Toolbar.Root.State) => ReactElement)
data-highlighted
Present when the button is the active item in the toolbar.
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the button is disabled.
data-focusable
Present when the button remains focusable when disabled.
Link
A link component.
Renders an <a>
element.
className
string | 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)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Toolbar.Link.State) => ReactElement)
data-highlighted
Present when the link is the active item in the toolbar.
data-orientation
Indicates the orientation of the toolbar.
Input
A native input element that integrates with Toolbar keyboard navigation.
Renders an <input>
element.
defaultValue
Union
Union
- Name
- Type
string | number | string[]
focusableWhenDisabled
boolean
(default: true
)
boolean
true
- Description
When
true
the item remains focuseable when disabled.- Type
boolean
- Default
true
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
When
true
the item is disabled.- Type
boolean
- Default
false
className
string | 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)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Toolbar.Root.State) => ReactElement)
data-highlighted
Present when the input is the active item in the toolbar.
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the input is disabled.
data-focusable
Present when the input remains focusable when disabled.
Group
Groups several toolbar items or toggles.
Renders a <div>
element.
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
When
true
all toolbar items in the group are disabled.- Type
boolean
- Default
false
className
string | 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)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Toolbar.Root.State) => ReactElement)
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the group is disabled.
Separator
A separator element accessible to screen readers.
Renders a <div>
element.
orientation
Orientation
(default: 'horizontal'
)
Orientation
'horizontal'
- Name
- Description
The orientation of the separator.
- Type
Orientation
- Default
'horizontal'
className
string | 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: Separator.State) => string)
render
ReactElement | 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
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Separator.State) => ReactElement)
data-orientation
Indicates the orientation of the toolbar.
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>
)