Toolbar
An unstyled toolbar component with compound composition for grouping actions.
Build fully custom toolbar layouts with complete control over content regions and styling.
Pre-styled Versions
Features#
- Compound component API with four sub-components:
Root,Start,Center,End - Three-region layout for start, center, and end content alignment
- Context sharing from
Rootto all descendant sub-components
Usage#
import { Toolbar } from 'primereact/toolbar';<Toolbar.Root>
<Toolbar.Start />
<Toolbar.Center />
<Toolbar.End />
</Toolbar.Root>Behavior#
Polymorphic Rendering#
Use as on any sub-component to change the rendered HTML element.
<Toolbar.Root as="nav">
<Toolbar.Start as="ul">...</Toolbar.Start>
</Toolbar.Root>Default elements: Root=div, Start=div, Center=div, End=div.
Render Function Children#
Sub-components accept a render function as children, providing access to the component instance.
<Toolbar.Start>{(instance) => <span>Toolbar ID: {instance.toolbar?.id}</span>}</Toolbar.Start>Pass Through#
Some parts may not be visible in the preview depending on the component's current state.
/* Select a part to see its CSS selector for custom styling */API#
ToolbarRoot#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ToolbarRootInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ToolbarRootInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ToolbarRootInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ToolbarRootPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ToolbarRootInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | toolbar |
data-part | root |
Defines passthrough(pt) options of Toolbar component.
| label | type | description |
|---|---|---|
| root | ToolbarRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
| start | ToolbarRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the start's DOM element. |
| center | ToolbarRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the center's DOM element. |
| end | ToolbarRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the end's DOM element. |
ToolbarStart#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ToolbarStartInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ToolbarStartInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ToolbarStartInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ToolbarStartPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ToolbarStartInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ToolbarStart component.
| label | type | description |
|---|---|---|
| root | ToolbarStartPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
ToolbarCenter#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ToolbarCenterInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ToolbarCenterInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ToolbarCenterInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ToolbarCenterPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ToolbarCenterInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ToolbarCenter component.
| label | type | description |
|---|---|---|
| root | ToolbarCenterPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
ToolbarEnd#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ToolbarEndInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ToolbarEndInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ToolbarEndInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ToolbarEndPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ToolbarEndInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ToolbarEnd component.
| label | type | description |
|---|---|---|
| root | ToolbarEndPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
Toolbar uses role="toolbar" on the root element. aria-orientation is not included as it defaults to "horizontal". Provide an accessible label via aria-label or aria-labelledby on Root.
Keyboard Support#
Component does not include built-in keyboard interaction. Keyboard behavior depends on interactive elements placed inside the toolbar (buttons, inputs, etc.). Follow the WAI-ARIA Toolbar Pattern for managing focus with arrow keys if needed.