Skip to content

Material 3

Components

Navigation bar

Navigation bars let people switch between UI views on smaller devices.

Eye RhymesGlass & Grace
Night DriveLuna Park
Slow MorningsThe Paper Kites
Field NotesAna Ortiz

Navigation bars let people switch between UI views on smaller devices. A navigation bar gives access to three to five destinations at the bottom of the window, each represented by an icon and label text. Use a navigation bar for:

  • Three to five main pages in the product
  • Mobile or tablet only

On larger devices, use a navigation rail instead.

A navigation bar is composed of these parts:

PartUse
NavigationBarThe bar, which holds the items
NavigationBarItemA destination, with its icon and label. See Slots.
import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { Text } from 'react-aria-components'

Basic navigation bar

Put one NavigationBarItem per destination in a NavigationBar, each with its icon and its label.

Home
import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Radio', 'radio'],
  ['Library', 'library_music'],
] as const

export default function Basic() {
  const [page, setPage] = useState<string>('Home')
  return (
    <div className="flex h-80 w-full flex-col">
      <div className="flex-1 overflow-y-auto p-space-300 text-headline-sm">{page}</div>
      <nav aria-label="Music">
        <NavigationBar>
          {destinations.map(([name, icon]) => (
            <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
              <Icon name={icon} />
              <Text slot="label">{name}</Text>
            </NavigationBarItem>
          ))}
        </NavigationBar>
      </nav>
    </div>
  )
}

The items can be vertical or horizontal. Set layout on the NavigationBar to vertical (the default) or horizontal.

Vertical items

A vertical item shows its label under its icon. Use vertical items in a compact window, like a phone.

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Library', 'library_music'],
] as const

export default function Vertical() {
  const [page, setPage] = useState<string>('Home')
  return (
    <div className="flex h-64 flex-col justify-end">
      <NavigationBar aria-label="Main">
        {destinations.map(([name, icon]) => (
          <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
            <Icon name={icon} />
            <Text slot="label">{name}</Text>
          </NavigationBarItem>
        ))}
      </NavigationBar>
    </div>
  )
}

Horizontal items

A horizontal item shows its icon and its label side by side. Use horizontal items in a medium window, like a tablet: set layout="horizontal" and arrangement="centered".

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Library', 'library_music'],
] as const

export default function Horizontal() {
  const [page, setPage] = useState<string>('Home')
  return (
    <div className="flex h-64 flex-col justify-end">
      <NavigationBar aria-label="Main" layout="horizontal" arrangement="centered">
        {destinations.map(([name, icon]) => (
          <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
            <Icon name={icon} />
            <Text slot="label">{name}</Text>
          </NavigationBarItem>
        ))}
      </NavigationBar>
    </div>
  )
}

Note: The bar does not switch its layout or its arrangement on its own as the window changes size.

Slots

  1. label
SlotChildUse
labelA TextThe label, which names the item

Write an item's icon and label as its children. The Icon is sized and colored by the item. A Text with another slot, or with none, throws an error.

For an item with an icon alone, set an aria-label.

Selection

Set isSelected on the NavigationBarItem of the view being shown, and handle a press with onChange or onPress. A selected item shows the active indicator and fills its Icon.

<NavigationBarItem isSelected={page === 'home'} onChange={() => setPage('home')}>
  <Icon name="home" />
  <Text slot="label">Home</Text>
</NavigationBarItem>
  • Your own state: Selecting an item does not deselect the others, and a press on the selected item calls onChange(false), so keep the selection in your own state.
  • Uncontrolled: With defaultSelected instead, an item keeps its own selection, and a second press turns it off.

Disabled

Set isDisabled on an item to disable it. It cannot be pressed, and the arrow keys skip it.

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Radio', 'radio'],
  ['Library', 'library_music'],
] as const

export default function Disabled() {
  const [page, setPage] = useState<string>('Home')
  return (
    <div className="flex h-64 flex-col justify-end">
      <NavigationBar aria-label="Main">
        {destinations.map(([name, icon]) => (
          <NavigationBarItem
            key={name}
            isSelected={page === name}
            isDisabled={name === 'Radio'}
            onChange={() => setPage(name)}
          >
            <Icon name={icon} />
            <Text slot="label">{name}</Text>
          </NavigationBarItem>
        ))}
      </NavigationBar>
    </div>
  )
}

Arrangement

Set arrangement to equal-weight (the default) or centered. It is independent of layout.

  • equal-weight divides the bar equally between the items. Use it in a compact window.
  • centered groups the items in the middle of the bar. Use it in a medium window. Three items take 60% of its width between them, four 70%, five 80%, six 90%, and seven or more all of it. An item whose content needs more room takes up to an equal share.
import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Radio', 'radio'],
  ['Library', 'library_music'],
] as const

export default function Arrangements() {
  const [page, setPage] = useState<string>('Home')
  const items = destinations.map(([name, icon]) => (
    <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
      <Icon name={icon} />
      <Text slot="label">{name}</Text>
    </NavigationBarItem>
  ))
  return (
    <div className="flex h-64 flex-col justify-end gap-space-300">
      <NavigationBar aria-label="Equal weight" layout="horizontal" arrangement="equal-weight">
        {items}
      </NavigationBar>
      <NavigationBar aria-label="Centered" layout="vertical" arrangement="centered">
        {items}
      </NavigationBar>
    </div>
  )
}

A component of your own between the bar and its items can render several items.

Placement

The bar is as wide as its container and is not positioned for you. Place it at the bottom of the window yourself:

  • In a column: Make the bar the last row of a column as tall as the window, under content that scrolls, as in this example.
  • Fixed: Or fix it to the bottom of the window, with className="fixed inset-x-0 bottom-0 z-navigation" on its <nav>. See Stacking order.

Song 1

Song 2

Song 3

Song 4

Song 5

Song 6

Song 7

Song 8

Song 9

Song 10

Song 11

Song 12

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = [
  ['Home', 'home'],
  ['Browse', 'explore'],
  ['Radio', 'radio'],
  ['Library', 'library_music'],
] as const

const rows = Array.from({ length: 12 }, (_, index) => (
  <p key={index} className="m-0 px-space-300 py-space-150 text-body-lg">
    Song {index + 1}
  </p>
))

export default function FixedPositioning() {
  const [page, setPage] = useState<string>('Home')
  return (
    <div className="flex h-80 flex-col">
      <div tabIndex={0} className="focus-ring-inset flex-1 overflow-y-auto">
        {rows}
      </div>
      <nav aria-label="Music player">
        <NavigationBar>
          {destinations.map(([name, icon]) => (
            <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
              <Icon name={icon} />
              <Text slot="label">{name}</Text>
            </NavigationBarItem>
          ))}
        </NavigationBar>
      </nav>
    </div>
  )
}

The bar is not a landmark. Put it in a <nav> of your own, or name it with an aria-label.

Third-party routing library

An item takes no href. To move between the pages of an app, call the router in the item's onChange or onPress, and set isSelected from the current location. See Routing.

With React Router:

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { Text } from 'react-aria-components'
import { useLocation, useNavigate } from 'react-router'

const destinations = [
  ['/', 'Home', 'home'],
  ['/browse', 'Browse', 'explore'],
  ['/library', 'Library', 'library_music'],
] as const

function MainNavigation() {
  const { pathname } = useLocation()
  const navigate = useNavigate()
  return (
    <nav aria-label="Main">
      <NavigationBar>
        {destinations.map(([path, name, icon]) => (
          <NavigationBarItem
            key={path}
            isSelected={pathname === path}
            onPress={() => navigate(path)}
          >
            <Icon name={icon} />
            <Text slot="label">{name}</Text>
          </NavigationBarItem>
        ))}
      </NavigationBar>
    </nav>
  )
}

Customization

Pass classes in className to restyle the bar or one item. A class of yours replaces the component's own class for the same property. See Styling for the classes, the states and the theme.

Pass a function as an item's children to render them from its state: isHovered, isPressed, isFocused, isFocusVisible, isSelected and isDisabled. In this example, an item shows another icon when it is selected.

import { Icon, NavigationBar, NavigationBarItem } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'

const destinations = ['Explore', 'Saved', 'Updates']

export default function FunctionChildren() {
  const [page, setPage] = useState('Saved')
  return (
    <div className="flex h-64 flex-col justify-end">
      <NavigationBar aria-label="Main">
        {destinations.map((name) => (
          <NavigationBarItem key={name} isSelected={page === name} onChange={() => setPage(name)}>
            {({ isSelected }) => (
              <>
                <Icon name={isSelected ? 'check_circle' : 'circle'} />
                <Text slot="label">{name}</Text>
              </>
            )}
          </NavigationBarItem>
        ))}
      </NavigationBar>
    </div>
  )
}
  • States: Style an item's state with its variant, such as hover:, pressed: or selected:. See States.
  • Functions: The className and style of an item can be functions of the same state, and the children of a NavigationBar can be a function too. See Children as a function.
  • Every navigation bar: To restyle all the navigation bars at once, change the theme.