FAB Menu
A FAB that opens into a short list of related actions. Tap it and the actions spring out of it one after another, nearest first, while the button shrinks to a round close button and its plus turns into a cross.
Install
npx shadcn@latest add @nelumbo/fab-menuCreate menu
Four to six actions, stacked above the FAB and aligned to its trailing edge. Items are tonal pills from the FAB's color family. Choosing one, or pressing Escape, closes the menu and returns focus to the button.
Notes
- Kitchen planMove the pantry wall 40 cm east so the island fits.
- GroceriesOat milk, lemons, basil, the good olive oil.
- Reading listDesigning Interfaces, The Shape of Design, Tools for Thought.
- Trip to LisbonBook the tram tour. Check the museum hours on Monday.
- StandupPush to 10:30. Site visit at 9.
- Gift ideasCeramic set for Hana, a linocut print for Leo.
Brand, with a scrim
color matches Fab. scrim dims the screen behind the open menu; a click on it closes the menu.
Notes
- Kitchen planMove the pantry wall 40 cm east so the island fits.
- GroceriesOat milk, lemons, basil, the good olive oil.
- Reading listDesigning Interfaces, The Shape of Design, Tools for Thought.
- Trip to LisbonBook the tram tour. Check the museum hours on Monday.
- StandupPush to 10:30. Site visit at 9.
- Gift ideasCeramic set for Hana, a linocut print for Leo.
Small, to the left
size="sm" and side="left" lay the actions out in a row beside the FAB, for a compact toolbar. The arrow keys work along either axis.
Notes
- Kitchen planMove the pantry wall 40 cm east so the island fits.
- GroceriesOat milk, lemons, basil, the good olive oil.
- Reading listDesigning Interfaces, The Shape of Design, Tools for Thought.
- Trip to LisbonBook the tram tour. Check the museum hours on Monday.
- StandupPush to 10:30. Site visit at 9.
- Gift ideasCeramic set for Hana, a linocut print for Leo.
Controlled
open and onOpenChange put the menu in your state. onSelect runs when an item is chosen; call event.preventDefault() in it to keep the menu open.
Menu is closed. Nothing chosen yet.
Notes
- Kitchen planMove the pantry wall 40 cm east so the island fits.
- GroceriesOat milk, lemons, basil, the good olive oil.
- Reading listDesigning Interfaces, The Shape of Design, Tools for Thought.
- Trip to LisbonBook the tram tour. Check the museum hours on Monday.
- StandupPush to 10:30. Site visit at 9.
- Gift ideasCeramic set for Hana, a linocut print for Leo.
Accessibility
The menu button pattern. The trigger has aria-haspopup=menu and aria-expanded; the list is role=menu with menuitem children, labelled by the trigger.
- Enter, Space or a click opens it and focuses the first item. ArrowDown and ArrowUp on the button open it too, to the first or last item.
- Arrow keys move between items and wrap. Home and End jump to the ends. Typing letters jumps to the next item that starts with them.
- Escape, choosing an item or Tab closes the menu; Escape and choosing return focus to the button.
- With prefers-reduced-motion, the items only fade: no travel, scale or rotation.
Usage
import { FabMenu, FabMenuTrigger, FabMenuContent, FabMenuItem } from "@/components/ui/fab-menu"<FabMenu color="brand" scrim className="fixed right-6 bottom-6"> <FabMenuTrigger icon="edit" label="Create" /> <FabMenuContent aria-label="Create"> <FabMenuItem icon="edit_note" onSelect={newNote}>New note</FabMenuItem> <FabMenuItem icon="checklist" onSelect={newList}>Checklist</FabMenuItem> <FabMenuItem icon="mic">Voice memo</FabMenuItem> </FabMenuContent></FabMenu>Props
| Prop | Type | Default | FabMenu holds the state and layout; the trigger is a Fab-styled button, so it takes Fab's color and size from the menu. |
|---|---|---|---|
color | "primary" | "secondary" | "brand" | "surface" | "solid" | "primary" | Same palette as Fab; items are tonal pills of it |
size | "sm" | "default" | "lg" | "default" | Trigger 40 / 56 / 96 px; open it shrinks to 40 / 48 / 56 |
side | "top" | "bottom" | "left" | "right" | "top" | Where the items go. left and right lay them in a row |
align | "start" | "center" | "end" | "end" | Along the FAB's edge |
scrim | boolean | false | Dim the page behind the menu; clicking it closes |
open / defaultOpen | boolean | false | Controlled / initial state |
onOpenChange | (open: boolean) => void | ||
FabMenuTrigger icon, closeIcon | IconName | "add", "close" | Closed and open glyphs |
FabMenuTrigger label | string | "Actions" | Accessible name |
FabMenuItem icon | IconName | required | |
FabMenuItem onSelect | (event: Event) => void | preventDefault() keeps the menu open | |
FabMenuItem disabled | boolean | false | Skipped by the arrow keys |