Hey! I’ve got pics and more info on our cabin for the weekend. Get ready to be impressed: it looks absolutely incredible from what I can see.
Toolbars display frequently used actions relevant to the current page. A toolbar holds controls such as:
- Icon buttons
- Buttons
- A button group
- Fields of your own
For the headline and navigation of a page, use an app bar instead.
import { Icon, IconButton, Toolbar } from '@material-web/react'Basic toolbar
Write the actions of a toolbar as its children. Choose its look with variant and color, and its direction with orientation.
Cabin for the weekend
Hey! I’ve got pics and more info on our cabin for the weekend. Get ready to be impressed: it looks absolutely incredible from what I can see.
import { Icon, IconButton, Toolbar } from '@material-web/react'
import { useState } from 'react'
export default function Basic() {
const [isStarred, setStarred] = useState(false)
return (
<div className="flex h-80 w-full flex-col">
<div className="flex-1 overflow-y-auto p-space-300">
<h3 className="m-0 text-title-lg">Cabin for the weekend</h3>
<p className="mt-space-100 mb-0 text-body-lg text-on-surface-variant">
Hey! I’ve got pics and more info on our cabin for the weekend. Get ready to be impressed:
it looks absolutely incredible from what I can see.
</p>
</div>
<Toolbar aria-label="Message">
<IconButton aria-label="Archive">
<Icon name="archive" />
</IconButton>
<IconButton aria-label="Delete">
<Icon name="delete" />
</IconButton>
<IconButton aria-label="Mark as unread">
<Icon name="mark_email_unread" />
</IconButton>
<IconButton aria-label="Star" isSelectable isSelected={isStarred} onChange={setStarred}>
<Icon name="star" className={isStarred ? 'icon-filled' : undefined} />
</IconButton>
</Toolbar>
</div>
)
}The toolbar has no interactions of its own. Handle each action on its element, such as in the onPress of an IconButton. See Handling presses.
The Toolbar comes in two variants. Set variant to docked (the default) for a toolbar across the bottom of the window, or to floating for a pill over the content.
Docked toolbar
A docked toolbar is best for global actions that remain the same across multiple pages. It is 64dp tall and as wide as its container.
It is not positioned for you. Place it at the bottom of the window yourself: as the last row of a column, as in the first example, or with className="fixed inset-x-0 bottom-0 z-navigation". Do not use a docked toolbar with another element at the bottom of the window, such as a navigation bar.
A docked toolbar spaces its elements evenly, with the first and the last 16dp from its ends.
- Other spacing: To space the elements another way, such as in a wider window, set
className. For example,justify-center gap-x-space-400centers them 32dp apart. - Flex row: Set
className="flex"to lay them out as a flex row instead, where each element is as wide as its content. Use it for aDividerbetween groups, or for an element that grows.
import { Button, Divider, Icon, IconButton, Toolbar } from '@material-web/react'
export default function DockedSpacing() {
return (
<div className="flex flex-col gap-space-300">
<Toolbar aria-label="Steps">
<Button variant="text">Back</Button>
<Button>Next</Button>
</Toolbar>
<Toolbar aria-label="Message" className="justify-center gap-x-space-400">
<IconButton aria-label="Archive">
<Icon name="archive" />
</IconButton>
<IconButton aria-label="Delete">
<Icon name="delete" />
</IconButton>
<IconButton aria-label="Snooze">
<Icon name="snooze" />
</IconButton>
</Toolbar>
<Toolbar aria-label="Editing" className="flex justify-start gap-x-space-150">
<IconButton aria-label="Undo">
<Icon name="undo" className="rtl:icon-mirrored" />
</IconButton>
<IconButton aria-label="Redo">
<Icon name="redo" className="rtl:icon-mirrored" />
</IconButton>
<Divider orientation="vertical" className="h-6 self-center" />
<IconButton aria-label="Insert link">
<Icon name="link" />
</IconButton>
<IconButton aria-label="Insert image">
<Icon name="image" />
</IconButton>
</Toolbar>
</div>
)
}Floating toolbar
A floating toolbar is best for contextual actions relevant to the body content or the specific page. It is only as big as its elements.
It is not positioned for you either. Float it yourself, such as with className="fixed bottom-space-200 left-1/2 -translate-x-1/2 z-fab", and keep it 16dp or more from the window's edge, or 24dp for a vertical one. See Stacking order.
Hey! I’ve got pics and more info on our cabin for the weekend. Get ready to be impressed: it looks absolutely incredible from what I can see.
import { Icon, IconButton, Toolbar } from '@material-web/react'
import { useState } from 'react'
export default function Floating() {
const [isBold, setBold] = useState(true)
const [isItalic, setItalic] = useState(false)
return (
<div className="relative h-80">
<div className="h-full overflow-y-auto p-space-300 text-body-lg">
<p className="m-0">
Hey! I’ve got pics and more info on our cabin for the weekend. Get ready to be impressed:
it looks absolutely incredible from what I can see.
</p>
</div>
<Toolbar
variant="floating"
aria-label="Formatting"
className="absolute bottom-space-200 left-1/2 -translate-x-1/2"
>
<IconButton aria-label="Bold" isSelectable isSelected={isBold} onChange={setBold}>
<Icon name="format_bold" />
</IconButton>
<IconButton aria-label="Italic" isSelectable isSelected={isItalic} onChange={setItalic}>
<Icon name="format_italic" />
</IconButton>
<IconButton aria-label="Text color">
<Icon name="format_color_text" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
</div>
)
}Elements
A toolbar shows its children in the order written. They can be icon buttons, Buttons, fields of your own, or a button group. Each element takes at least 48dp of the row, and a wider one takes its own width.
import { Button, ButtonGroup, Icon, IconButton, Toolbar } from '@material-web/react'
const formats = [
['bold', 'Bold', 'format_bold'],
['italic', 'Italic', 'format_italic'],
['underline', 'Underline', 'format_underlined'],
] as const
const pages = ['Photos', 'Memories', 'Library']
export default function WithButtonGroup() {
return (
<>
<Toolbar variant="floating" aria-label="Formatting">
<ButtonGroup
aria-label="Text style"
selectionMode="multiple"
defaultSelectedKeys={['bold']}
>
{formats.map(([id, label, icon]) => (
<IconButton key={id} id={id} aria-label={label} isSelectable>
<Icon name={icon} />
</IconButton>
))}
</ButtonGroup>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
<Toolbar variant="floating" aria-label="Pages">
<ButtonGroup
aria-label="Page"
defaultSelectedKeys={['Photos']}
disallowEmptySelection
className="gap-space-50"
>
{pages.map((name) => (
<Button key={name} id={name} variant="tonal" isSelectable>
{name}
</Button>
))}
</ButtonGroup>
</Toolbar>
</>
)
}Note: Avoid square icon buttons in a floating toolbar. Their shape conflicts with the fully rounded shape of its container.
Disabled
Set isDisabled on an element of the toolbar to disable it. The arrow keys skip a disabled element.
import { Icon, IconButton, Toolbar } from '@material-web/react'
const colors = ['standard', 'vibrant'] as const
export default function Disabled() {
return (
<>
{colors.map((color) => (
<Toolbar key={color} variant="floating" color={color} aria-label={`Call, ${color}`}>
<IconButton aria-label="Turn camera on">
<Icon name="videocam_off" />
</IconButton>
<IconButton aria-label="Mute" isDisabled>
<Icon name="mic" />
</IconButton>
<IconButton aria-label="Captions" isSelectable defaultSelected isDisabled>
<Icon name="closed_caption" className="icon-filled" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
))}
</>
)
}Color
Set color to choose between two color schemes:
standard(the default) is a low-emphasis scheme, which keeps the attention on the body content.vibrantis a high-emphasis scheme that draws attention to the controls, and shows the toolbar in the primary container color. It can also indicate a temporary change in the page, such as entering edit mode.
import { Icon, IconButton, Toolbar } from '@material-web/react'
const colors = ['standard', 'vibrant'] as const
export default function Colors() {
return (
<>
{colors.map((color) => (
<Toolbar key={color} variant="floating" color={color} aria-label={`Formatting, ${color}`}>
<IconButton aria-label="Bold" isSelectable defaultSelected>
<Icon name="format_bold" />
</IconButton>
<IconButton aria-label="Italic" isSelectable>
<Icon name="format_italic" />
</IconButton>
<IconButton aria-label="Underline" isSelectable>
<Icon name="format_underlined" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
))}
</>
)
}The toolbar colors every toggle in it, whatever the toggle's own variant: an IconButton or a Button with isSelectable, and the buttons of a ButtonGroup. A toggle is flat until it is selected. A selected toggle is shown in a container and keeps its round shape.
Emphasis
A button that is not a toggle keeps the colors of its own variant. To emphasize an action, use a filled IconButton or a text Button.
import { Button, Icon, IconButton, Toolbar } from '@material-web/react'
export default function Emphasis() {
return (
<>
<Toolbar variant="floating" aria-label="Browser">
<IconButton aria-label="Back">
<Icon name="arrow_back" className="rtl:icon-mirrored" />
</IconButton>
<IconButton aria-label="Forward">
<Icon name="arrow_forward" className="rtl:icon-mirrored" />
</IconButton>
<IconButton aria-label="New tab" variant="filled" width="wide">
<Icon name="add" />
</IconButton>
<IconButton aria-label="Tabs">
<Icon name="tab" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
<Toolbar variant="floating" aria-label="Draft">
<IconButton aria-label="Attach a file">
<Icon name="attach_file" />
</IconButton>
<IconButton aria-label="Insert image">
<Icon name="image" />
</IconButton>
<Button variant="text">Send</Button>
</Toolbar>
</>
)
}Elevation
A floating toolbar has a shadow. Set className="shadow-none" to remove it, such as over content that is visually distinct.
import { Icon, IconButton, Toolbar } from '@material-web/react'
export default function NoElevation() {
return (
<div className="rounded-shape-xl bg-surface-container-highest p-space-400">
<Toolbar variant="floating" color="vibrant" aria-label="Formatting" className="shadow-none">
<IconButton aria-label="Bold" isSelectable defaultSelected>
<Icon name="format_bold" />
</IconButton>
<IconButton aria-label="Italic" isSelectable>
<Icon name="format_italic" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
</div>
)
}Orientation
Set orientation="vertical" on a floating toolbar to make it a column, 64dp wide. The up and down arrow keys then move between its elements.
import { Icon, IconButton, Toolbar } from '@material-web/react'
const colors = ['standard', 'vibrant'] as const
export default function Vertical() {
return (
<>
{colors.map((color) => (
<Toolbar
key={color}
variant="floating"
orientation="vertical"
color={color}
aria-label={`Call, ${color}`}
>
<IconButton aria-label="Camera" isSelectable defaultSelected>
<Icon name="videocam" />
</IconButton>
<IconButton aria-label="Microphone" isSelectable>
<Icon name="mic" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
))}
</>
)
}- Width: To keep a vertical toolbar compact, do not use wide icon buttons in it.
- Window size: A vertical toolbar is not recommended for a compact window.
Toolbar with FAB
To present one high-priority action alongside the actions of a floating toolbar, put a Fab beside the toolbar, not in it, 8dp away (gap-space-100). Choose the FAB's color, such as secondary-container or tertiary-container.
import { Fab, Icon, IconButton, Toolbar } from '@material-web/react'
export default function WithFab() {
return (
<div className="flex items-center gap-space-100">
<Toolbar variant="floating" aria-label="Call">
<IconButton aria-label="Turn camera on">
<Icon name="videocam_off" />
</IconButton>
<IconButton aria-label="Mute">
<Icon name="mic" />
</IconButton>
<IconButton aria-label="More">
<Icon name="more_vert" />
</IconButton>
</Toolbar>
<Fab aria-label="Reply" color="tertiary-container">
<Icon name="reply" className="rtl:icon-mirrored" />
</Fab>
</div>
)
}Toolbar with menu
Elements that do not fit are not moved into an overflow menu. If more actions are needed, add the menu yourself: wrap the last IconButton and a MenuPopover in a MenuTrigger.
import { Icon, IconButton, Menu, MenuItem, MenuPopover, Toolbar } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'
export default function OverflowMenu() {
return (
<Toolbar variant="floating" aria-label="Message">
<IconButton aria-label="Archive">
<Icon name="archive" />
</IconButton>
<IconButton aria-label="Delete">
<Icon name="delete" />
</IconButton>
<MenuTrigger>
<IconButton aria-label="More actions">
<Icon name="more_vert" />
</IconButton>
<MenuPopover>
<Menu>
<MenuItem>Mark as unread</MenuItem>
<MenuItem>Snooze</MenuItem>
<MenuItem>Move to</MenuItem>
</Menu>
</MenuPopover>
</MenuTrigger>
</Toolbar>
)
}Customization
Pass classes in className to restyle one toolbar. A class of yours replaces the toolbar's own class for the same property. See Styling for the classes and the theme.
- Functions: The
className,styleandchildrenof a toolbar can be functions of itsorientation. See Children as a function. - Every toolbar: To restyle all the toolbars at once, change the theme.
Use cases
Material lists what people should be able to do with assistive technology:
- Navigate and activate any actions in the toolbar
- Select a destination from a menu
- Activate a back button
- Maintain access to toolbar controls when the content is scrolled or collapsed
Interaction and style
- States: The toolbar has no states of its own, as Material notes: each element shows its own state layer, ripple and focus ring. An arrow key that moves the focus shows the ring on the element it reaches.
- Touch target: Each element is centered in a cell at least 48dp wide and tall, so that the 48dp touch targets of its elements do not overlap.
- Color contrast: In both
colorschemes, the elements keep 3:1 contrast with what they are on and their labels 4.5:1, a selected toggle on its container included, in the light and dark schemes at every contrast level. - Forced colors: In forced colors, a floating toolbar keeps an edge, and a selected toggle in it is filled with the system's highlight color.
- Right to left: The elements are laid out from the right in a right-to-left direction.
Focus
- Tab moves the focus into the toolbar once: to its first element, as Material advises, or to the element focused last. The next Tab leaves the toolbar, and Shift+Tab comes back to the element it left.
- The focus moves through the elements in the order written, which is the order shown.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus into the toolbar, or out of it |
| Left or Right arrow | Move the focus to the previous or next element |
| Up or Down arrow | Move the focus to the previous or next element of a vertical toolbar |
| Space or Enter | Activate the focused element |
- The arrow keys move between its elements, a text field included. They skip a disabled element, and stop at the first and the last. In a vertical toolbar, the left and right arrow keys do not move the focus.
- The left and right arrow keys are reversed in a right-to-left locale, which is set with an
I18nProvider, not withdir. - The same keys move through the buttons of a
ButtonGroupin the toolbar, on to the elements after it and back.
Labeling elements
- The toolbar has the toolbar role, as Material advises on the web, and reports its orientation with
aria-orientation. Name the toolbar witharia-labeloraria-labelledby. - Label each element as its own component asks, as Material also advises. An
IconButtonneeds anaria-label: see Icon button. - A
ButtonGroupin the toolbar is a group, or a radio group with single selection. Name it with anaria-label.
variant'docked' | 'floating'Default'docked'There are two variants of toolbars:
docked: Spans the full width of the window. It’s best used for global actions that remain the same across multiple pages.floating: Floats above the body content. It’s best used for contextual actions relevant to the body content or the specific page.
The docked toolbar’s container spans the full width of the window.
Avoid applying rounded corners to the container. This can imply the container expands or changes upon interaction.
As long as there's a minimum of 16dp padding on the leading and trailing edge, arrange controls inside however you see fit. The 32dp padding between items is just the default.
Only place docked toolbars at the bottom of the window.
If using other bottom-aligned elements, such as a navigation bar, don't use a docked toolbar.
In compact breakpoints, elements in the toolbar should be evenly spaced.
In medium breakpoints and larger, adjust the padding between controls to create a comfortable layout.
The floating toolbar’s container should be fully visible on screen. If more actions are needed, use an overflow menu.
The container should only be as big as needed to hold the items inside before reaching the 16dp margin.
Floating toolbars have elevation by default.
If the content beneath the toolbar is visually distinct, elevation can be removed.
Floating toolbars can be horizontal or vertical.
Horizontal toolbars should have a minimum 16dp margin from the edge of the window.
Vertical toolbars should have a minimum 24dp margin.
To keep vertical toolbars compact, don’t use wide icon buttons.
Vertical toolbars aren’t recommended for compact windows.
Avoid using square icon buttons in floating toolbars. Their square shape conflicts with the fully-rounded shape of the floating toolbar container.
A FAB can be placed next to a floating toolbar to present one high-priority action alongside a unified set of toolbar actions.
color'standard' | 'vibrant'Default'standard'There are two color configurations:
standard: A low-emphasis color scheme best used for focusing attention on the body content.vibrant: A high-emphasis color scheme that draws attention to the controls. It can also indicate a temporary change in the page behavior, such as entering edit mode.
Props of Toolbar (11)
classNameClassNameOrFunction<ToolbarRenderProps>Default'react-aria-Toolbar'The CSS className for the element. A function may be provided to compute the class based on component state.
orientation'horizontal' | 'vertical'Default'horizontal'The orientation of the entire toolbar.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: ToolbarRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', ToolbarRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
refRef<HTMLDivElement>
Toolbar also takes the 70 attributes and events of the element it renders.