FAB menu
ExpressiveA FAB that opens two to six related actions above it, or a menu on the web.
import { FabMenu, FabMenuItem } from '@windmorph/react';Props
FabMenu 20 props
The button's icon while closed, usually "add". Hidden from assistive tech.
Two to six
FabMenuItemelements, top to bottom.Whether the menu is open (controlled).
Whether the menu starts open (uncontrolled).
The button's icon while open, usually "close". Defaults to
icon.How the button hands over from
icontoopenIcon:swaphalfway through the morph (the M3 spec and Compose), orrotate, where the outgoing icon turns 90° and fades out while the incoming one turns in and fades in.rotategoes beyond the M3 spec; it matches Google's Expressive showcase motion. It mirrors in RTL, and reduced motion keeps only the crossfade. Only used withopenIcon.The FAB size the button starts at; open, it is always the 56px close button.
The button's and items' colour scheme, from M3's FAB menu colour sets.
The button's and items' elevation, as on
Fab: level 3 by default (the spec),loweredlevel 1, orflatlevel 0.How the items show:
list, the expressive stack of pills above the button, ormenu, a standard menu 4px above it (M3's choice for the web and large windows).While closed, shows
aria-labelin a plain tooltip on hover and keyboard focus, as M3 asks of FABs on the web. Open, the button is the close button and has no tooltip. It steps aside inside your ownTooltipTrigger.Shows the button. Hiding it closes the menu, shrinks the button towards its centre and fades it out; showing it expands it back (the FAB's appear / disappear motion). A hidden menu is
inert.Plays the appearing animation when the menu mounts. Change its
keyon a page or tab change to replay it.Ref to the root element.
Text
Accessible name for the button, also its tooltip. Required unless
aria-labelledbyis set.The id of the element that names the button.
One of
aria-labeloraria-labelledbyis required.
Classes for each part, by slot.
The outer container, merged with
className.The box that keeps the FAB's size while the button shrinks inside it.
The button's icon.
The list of items (
presentation="list").The built-in plain tooltip shown on the closed button (
tooltip).
Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
FabMenuItem 17 props
The label, which M3 always requires.
The item's icon. Hidden from assistive tech; the label names the item. M3 asks for an icon on every item, since it tells the items apart; leave it out only if necessary.
Ref to the root element: the
<button>, or the<a>withhref.The value a submit button sends with its form, under its
name. On a toggle (toggle) it's astringnaming the button in a selection group instead, required to take part in the group's selection.The element is being dragged (e.g. a card picked up to move it): sets
data-draggedfor the dragged state layer. A consumer's owndata-draggedattribute counts too.Don't move focus to the element on press (set by menu triggers).
The element rendered: a native
<button>.Renders a link. Navigation goes through React Aria's
RouterProviderwhen one is set.
Events
Runs when the item is chosen, in either presentation. (
onPressworks only in the list, since a menu item has no press event.)
Classes for each part, by slot.
Inline styles for the root element.
Classes for the root element, merged with
classNames.root; consumer classes win.
Handler that is called when the press is released over the target.
Handler that is called when a press interaction starts.
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
Handler that is called when the press state changes.
Handler that is called when a press is released over the target, regardless of whether it started on the target or not.
Also accepts every <a> or <button> attribute.
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-fab-menu-close-button-container-shape | 28px | The open close button’s corners (half its 56px size, so they animate). | FabMenuBaselineTokens.CloseButtonContainerShape |
--md-comp-fab-menu-menu-item-container-shape | var(--md-sys-shape-corner-full) | The corners of the list’s items. | FabMenuBaselineTokens.ListItemContainerShape |
| Primary (color) | |||
--md-comp-fab-menu-primary-close-button-container-color | var(--md-sys-color-primary) | The open close button. | |
--md-comp-fab-menu-primary-close-button-icon-color | var(--md-sys-color-on-primary) | The open close button’s icon. | |
| Secondary (color) | |||
--md-comp-fab-menu-secondary-close-button-container-color | var(--md-sys-color-secondary) | The open close button. | |
--md-comp-fab-menu-secondary-close-button-icon-color | var(--md-sys-color-on-secondary) | The open close button’s icon. | |
| Tertiary (color) | |||
--md-comp-fab-menu-tertiary-close-button-container-color | var(--md-sys-color-tertiary) | The open close button. | |
--md-comp-fab-menu-tertiary-close-button-icon-color | var(--md-sys-color-on-tertiary) | The open close button’s icon. | |
| Primary-container (item-color) | |||
--md-comp-fab-menu-primary-container-list-item-container-color | var(--md-sys-color-primary-container) | The list’s items. | |
--md-comp-fab-menu-primary-container-list-item-label-text-color | var(--md-sys-color-on-primary-container) | The items’ labels. | |
--md-comp-fab-menu-primary-container-list-item-icon-color | var(--md-sys-color-on-primary-container) | The items’ icons. | |
| Secondary-container (item-color) | |||
--md-comp-fab-menu-secondary-container-list-item-container-color | var(--md-sys-color-secondary-container) | The list’s items. | |
--md-comp-fab-menu-secondary-container-list-item-label-text-color | var(--md-sys-color-on-secondary-container) | The items’ labels. | |
--md-comp-fab-menu-secondary-container-list-item-icon-color | var(--md-sys-color-on-secondary-container) | The items’ icons. | |
| Tertiary-container (item-color) | |||
--md-comp-fab-menu-tertiary-container-list-item-container-color | var(--md-sys-color-tertiary-container) | The list’s items. | |
--md-comp-fab-menu-tertiary-container-list-item-label-text-color | var(--md-sys-color-on-tertiary-container) | The items’ labels. | |
--md-comp-fab-menu-tertiary-container-list-item-icon-color | var(--md-sys-color-on-tertiary-container) | The items’ icons. | |
Spec status
Built to the M3 Expressive fab menu spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| FAB menu | Built | Variant · Basic |
| Color: primary, secondary, tertiary set | Built | Configuration · Colors |
| Opening from a medium or large FAB | Built | Configuration · Web |
| A menu on the web | Built | Use case · Web |
| Outside press closes it | Extension | Compose relies on the system back button, which the web doesn't have, so an outside press closes the menu too. |
| Appear and disappear | Extension | visible and appear give the menu's FAB the FAB's own disappear and reappear motion. |
iconTransition="rotate" | Extension | Not in the M3 spec, which swaps icon for openIcon halfway through the morph: the outgoing icon turns 90° counter-clockwise on open (mirrored in RTL) and fades out as the incoming one turns in. Matches Google's Expressive showcase motion; reduced motion keeps only the crossfade. |
elevation | Extension | As on Fab: lowered (level 1) or flat (level 0, the spec's level for a FAB nested in another surface) for the button and its items. |
FAB menu
BuiltVariant · Basic
Color: primary, secondary, tertiary set
BuiltConfiguration · Colors
Opening from a medium or large FAB
BuiltConfiguration · Web
A menu on the web
BuiltUse case · Web
Outside press closes it
ExtensionCompose relies on the system back button, which the web doesn't have, so an outside press closes the menu too.
Appear and disappear
Extensionvisibleandappeargive the menu's FAB the FAB's own disappear and reappear motion.
ExtensioniconTransition="rotate"Not in the M3 spec, which swaps
iconforopenIconhalfway through the morph: the outgoing icon turns 90° counter-clockwise on open (mirrored in RTL) and fades out as the incoming one turns in. Matches Google's Expressive showcase motion; reduced motion keeps only the crossfade.
ExtensionelevationAs on
Fab:lowered(level 1) orflat(level 0, the spec's level for a FAB nested in another surface) for the button and its items.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
FabMenu,FabMenuItem: 48.4 kB
M3 Expressive specs
- Shape
rounded-corner-large- Elevation
level3
Spec values and differences
- No shape morph: Compose's FAB menu does not use the shape library.
- The toggle button keeps its FAB's layout box (56 / 80 / 96px) in a library-owned anchor; open, it becomes the 56px close button with 28px corners and a 20px icon. Size, corners and icon follow the fast spatial spring; the colours move from the
*-containerrole to the vibrant role on the fast effects spring, so they never overshoot. - Items are 56px pills (min 56px wide, 24px padding, 8px icon gap, 24px icon,
title-medium), 4px apart and 8px above the button. - The button and the items sit at level 3, as the spec asks;
elevationworks as onFab, withlowered(level 1) andflat(level 0). iconTransition="rotate"goes beyond the spec, which swaps the icons halfway through the morph: the icons turn 90° counter-clockwise as the menu opens (mirrored in RTL) while they crossfade, and turn back as it closes. Reduced motion keeps only the crossfade.- Opening staggers the visible item count on the slow effects spring (the item nearest the button appears first); each item then springs its width on fast spatial and its opacity on fast effects. Closing hides the top item first.
- Colour sets are
primary | secondary | tertiary(m3.material.io's sets; Compose's default is primary). - A development warning flags a menu with fewer than two or more than six items.