Skip to content

Material 3

Components

FAB menu

FAB menus open from a FAB to display multiple related actions.

Trip planEdited yesterday
Budget 2025Edited on Monday
Photos48 items
Meeting notesEdited last week
Recipes12 items
Reading listEdited in May

A FAB menu opens from a FAB to show multiple related actions. It can hold two to six items, closely related under a single action, like Share.

For a single action, use a FAB alone. For a menu opened from another button, use a menu.

A FAB menu is written as a menu, with these parts in a MenuTrigger:

PartInUse
FabMenuButtonMenuTriggerThe FAB, first in the trigger. Write its icon as its children. While the menu is open, it shows a close icon instead.
FabMenuPopoverMenuTriggerHolds the menu, after the FabMenuButton
FabMenuFabMenuPopoverThe list of items
FabMenuItemFabMenuOne item of the list
import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

Basic FAB menu

Put a FabMenuButton first in a MenuTrigger, and a FabMenuPopover after it. In the popover, write a FabMenu with a FabMenuItem for each action.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

export default function Basic() {
  return (
    <div className="box-border flex h-80 w-full items-end justify-end p-space-200">
      <MenuTrigger>
        <FabMenuButton aria-label="Create">
          <Icon name="add" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu>
            <FabMenuItem textValue="Email">
              <Icon name="mail" />
              Email
            </FabMenuItem>
            <FabMenuItem textValue="Message">
              <Icon name="chat" />
              Message
            </FabMenuItem>
            <FabMenuItem textValue="Folder">
              <Icon name="folder" />
              Folder
            </FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}

Press the FAB to open the menu. Press the close button, Escape or anywhere outside the menu to close it.

Items

Write an item's icon and then its label as its children. An item looks like a tonal medium button.

Typing finds an item by its textValue. An item whose children are a plain string uses that string. Any other item, such as one with an icon, requires a textValue.

Only the label is required on an item. The icons make each item easy to identify and tell the items apart, so remove them only if necessary.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

export default function WithoutIcons() {
  return (
    <div className="box-border flex h-80 w-full items-end justify-end p-space-200">
      <MenuTrigger>
        <FabMenuButton aria-label="Create">
          <Icon name="add" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu>
            <FabMenuItem>Email</FabMenuItem>
            <FabMenuItem>Message</FabMenuItem>
            <FabMenuItem>Folder</FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}

Handling actions

Give each item an id. The onAction of the FabMenu is called with the id of the item that is chosen, and the item's own onAction is called too. Choosing an item closes the menu. Give an item an href to make it a link.

No action yet

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { useState } from 'react'
import { MenuTrigger, type Key } from 'react-aria-components'

export default function Actions() {
  const [last, setLast] = useState<Key>()
  return (
    <div className="box-border flex h-80 w-full items-end justify-between p-space-200">
      <p className="m-0 text-body-md text-on-surface-variant">
        {last ? `Last action: ${last}` : 'No action yet'}
      </p>
      <MenuTrigger>
        <FabMenuButton aria-label="Share">
          <Icon name="share" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu onAction={setLast}>
            <FabMenuItem id="link" textValue="Copy link">
              <Icon name="link" />
              Copy link
            </FabMenuItem>
            <FabMenuItem id="email" textValue="Email">
              <Icon name="mail" />
              Email
            </FabMenuItem>
            <FabMenuItem id="print" textValue="Print">
              <Icon name="print" />
              Print
            </FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}

Opening and closing

A FAB menu opens and closes as a menu does. To control it, set isOpen and onOpenChange on the MenuTrigger.

The menu is closed

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { useState } from 'react'
import { MenuTrigger } from 'react-aria-components'

export default function Controlled() {
  const [isOpen, setOpen] = useState(false)
  return (
    <div className="box-border flex h-80 w-full items-end justify-between p-space-200">
      <p className="m-0 text-body-md text-on-surface-variant">
        {isOpen ? 'The menu is open' : 'The menu is closed'}
      </p>
      <MenuTrigger isOpen={isOpen} onOpenChange={setOpen}>
        <FabMenuButton aria-label="Create">
          <Icon name="add" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu>
            <FabMenuItem textValue="Email">
              <Icon name="mail" />
              Email
            </FabMenuItem>
            <FabMenuItem textValue="Message">
              <Icon name="chat" />
              Message
            </FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}

While the menu is open, the rest of the page is inert and hidden from assistive technology.

Tab keeps the focus in the menu. Escape, choosing an item or a press outside the menu closes it, and the focus returns to the FAB.

Loading

Set isPending on the FabMenuButton while an action from the menu is in progress, as on a FAB. A pending FAB shows a loading indicator in place of its icon, sized to the FAB. It keeps its size and colors, so the layout around it does not shift.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { useState } from 'react'
import { MenuTrigger } from 'react-aria-components'

export default function Loading() {
  const [isUploading, setUploading] = useState(false)
  const upload = async () => {
    setUploading(true)
    await new Promise((resolve) => setTimeout(resolve, 3000))
    setUploading(false)
  }
  return (
    <div className="box-border flex h-80 w-full items-end justify-end p-space-200">
      <MenuTrigger>
        <FabMenuButton aria-label="Upload" isPending={isUploading}>
          <Icon name="upload" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu onAction={upload}>
            <FabMenuItem textValue="Photo">
              <Icon name="image" />
              Photo
            </FabMenuItem>
            <FabMenuItem textValue="Document">
              <Icon name="description" />
              Document
            </FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}
  • Presses: A pending FAB ignores presses and shows no hover, so it does not open the menu.
  • Focus: It keeps the focus, so a keyboard user who chose an item stays on the FAB while the action runs.
  • Children: Its icon is hidden while it is pending. See Pending content.

Disabled

Set isDisabled on the FabMenuButton to disable the whole menu: the FAB cannot open it. Set isDisabled on a FabMenuItem to disable that item: the keyboard skips it, and it cannot be pressed.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

export default function Disabled() {
  return (
    <div className="box-border flex h-80 w-full items-end justify-center gap-space-600 p-space-200">
      <MenuTrigger>
        <FabMenuButton aria-label="Create, disabled" isDisabled>
          <Icon name="add" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu>
            <FabMenuItem>Email</FabMenuItem>
            <FabMenuItem>Message</FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
      <MenuTrigger>
        <FabMenuButton aria-label="Create">
          <Icon name="add" />
        </FabMenuButton>
        <FabMenuPopover>
          <FabMenu>
            <FabMenuItem textValue="Email">
              <Icon name="mail" />
              Email
            </FabMenuItem>
            <FabMenuItem textValue="Message" isDisabled>
              <Icon name="chat" />
              Message
            </FabMenuItem>
            <FabMenuItem textValue="Folder">
              <Icon name="folder" />
              Folder
            </FabMenuItem>
          </FabMenu>
        </FabMenuPopover>
      </MenuTrigger>
    </div>
  )
}

Color

Set color to primary (the default), secondary or tertiary. Set it on the FabMenuButton and on the FabMenu, which colors its items, and give both the same value. Use primary with the primary or primary container FAB color styles, secondary with the secondary ones and tertiary with the tertiary ones.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

const colors = ['primary', 'secondary', 'tertiary'] as const

export default function Colors() {
  return (
    <div className="box-border flex h-80 w-full items-end justify-center gap-space-600 p-space-200">
      {colors.map((color) => (
        <MenuTrigger key={color}>
          <FabMenuButton color={color} aria-label={`Create, ${color}`}>
            <Icon name="add" />
          </FabMenuButton>
          <FabMenuPopover>
            <FabMenu color={color}>
              <FabMenuItem textValue="Email">
                <Icon name="mail" />
                Email
              </FabMenuItem>
              <FabMenuItem textValue="Message">
                <Icon name="chat" />
                Message
              </FabMenuItem>
            </FabMenu>
          </FabMenuPopover>
        </MenuTrigger>
      ))}
    </div>
  )
}

Sizes

Set size on the FabMenuButton to baseline (the default), medium or large, the sizes of a Fab. It sets the size of the FAB only: the close button and the items are the same size for all three.

import { FabMenu, FabMenuButton, FabMenuItem, FabMenuPopover, Icon } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

const sizes = ['baseline', 'medium', 'large'] as const

export default function Sizes() {
  return (
    <div className="box-border flex h-80 w-full items-end justify-center gap-space-600 p-space-200">
      {sizes.map((size) => (
        <MenuTrigger key={size}>
          <FabMenuButton size={size} aria-label={`Create, ${size}`}>
            <Icon name="add" />
          </FabMenuButton>
          <FabMenuPopover>
            <FabMenu>
              <FabMenuItem textValue="Email">
                <Icon name="mail" />
                Email
              </FabMenuItem>
              <FabMenuItem textValue="Message">
                <Icon name="chat" />
                Message
              </FabMenuItem>
            </FabMenu>
          </FabMenuPopover>
        </MenuTrigger>
      ))}
    </div>
  )
}

Placement

The FabMenuButton does not position itself. Place it with its className, such as fixed right-space-200 bottom-space-200 z-fab for the corner of the window. The examples on this page put it at the end of a box instead.

<MenuTrigger>
  <FabMenuButton
    aria-label="Create"
    color="tertiary"
    className="fixed right-space-200 bottom-space-200 z-fab"
  >
    <Icon name="add" />
  </FabMenuButton>
  <FabMenuPopover>
    <FabMenu color="tertiary">
      <FabMenuItem id="email" textValue="Email" onAction={compose}>
        <Icon name="mail" />
        Email
      </FabMenuItem>
      <FabMenuItem id="message" textValue="Message" href="/chats/new">
        <Icon name="chat" />
        Message
      </FabMenuItem>
    </FabMenu>
  </FabMenuPopover>
</MenuTrigger>

The FabMenuPopover opens above the end of the FAB. Set its placement to change that: it is top end by default. It does not flip below the FAB.

Note: The FAB must stay above the items. Place the FabMenuButton where none of its ancestors creates a stacking context, such as fixed at the corner of the window.

Size and scrolling

The menu is as tall as the room above the FAB allows, up to the top edge of the window. When the items do not fit, the list scrolls behind the close button, which stays in view.

The list opens scrolled to the item nearest the FAB, unless the keyboard opened it with the first item focused.

Customization

Pass classes in the className of a part to restyle it. A class of yours replaces the part's own class for the same property. See Styling for the classes, the states and the theme.

  • Transitions: To style the FabMenuPopover while it opens or closes, use the entering: and exiting: variants, or its data-entering and data-exiting attributes in your own CSS.
  • Every FAB menu: To restyle all the FAB menus at once, change the theme.

Children as a function

Pass a function as the children of a part to render them from its state:

  • FabMenuButton: isHovered, isPressed, isFocused, isFocusVisible, isDisabled and isPending. isPressed is also true while the menu is open. Its className and style can be functions of the same state.
  • FabMenuPopover: isEntering, isExiting, placement and trigger.
  • FabMenuItem: isHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled, hasSubmenu and isOpen. On an item, isFocused is focus from the keyboard or the pointer, and isFocusVisible is keyboard focus only.
  • FabMenu: with items, pass a function that renders each item.

The states' types are exported as FabMenuButtonRenderProps and FabMenuItemRenderProps. See Children as a function.

Limitations

Presses on the FAB

The onPress of the FabMenuButton is not called for every press. A mouse or the keyboard opens the menu without calling it, and a press on the close button closes the menu without calling it. To run code when the menu opens or closes, use onOpenChange on the MenuTrigger.

Pending content

A pending FAB shows only its loading indicator. Children written for the pending state, such as a different icon, are hidden too. For a button that shows other content while pending, build a complex button.