Skip to content

Material 3

Components

Toolbar

Toolbars display frequently used actions relevant to the current page.

Cabin for the weekendSSandra Adamsto me

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:

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-400 centers 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 a Divider between 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.
  • vibrant is 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, style and children of a toolbar can be functions of its orientation. See Children as a function.
  • Every toolbar: To restyle all the toolbars at once, change the theme.