Skip to content

Menu

A temporary list of choices anchored to a trigger, with groups, selection, submenus and context menus, or a bottom sheet on phones.

import { Menu, MenuItem, MenuGroup, MenuTrigger, SubmenuTrigger, ContextMenuTrigger } from '@windmorph/react';

Props

By name or description, across the 64 props below

Menu 31 props

  • childrentype ReactNodeRequired

    MenuItems, MenuGroups and SubmenuTriggers.

  • deselectabletype booleandefault true

    With selectionMode: the last selected item can be deselected, leaving none. false keeps at least one item selected.

  • disabledKeystype Iterable<Key>

    The keys of items that can't be chosen. They stay focusable, as M3 asks ("Disabled menu items can receive focus but aren't selectable").

  • varianttype "standard" | "vibrant"default "standard"

    standard (surface colours) or vibrant (tertiary container). A submenu shown in place (in a sheet, or with submenuPresentation="replace") takes the root menu's: a menu's pages share one variant, so a page never looks different from the one that opened it, and the same in a popover and in a sheet.

  • layouttype "divider" | "gap"default "divider"

    How groups are set apart. divider: one surface with dividers between groups, which M3 recommends on the web and for menus that scroll. gap: each group is its own surface, 2px apart; a gap menu that has to scroll switches to dividers, since M3 doesn't use gaps in scrolling menus. A submenu beside its item takes its parent's layout and variant unless it sets its own; shown in place, it takes the divider layout and the root's variant.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density (M3: "On web only … Increasing density decreases the top and bottom padding"): each step down takes 4px off the items' height (44px at 0, 32px at -3) and 2px off the space around dividers. Left out, the menu takes the density of the nearest ThemeProvider or ThemeScope; a submenu takes its parent menu's. Keep 0 for touch.

  • placementtype "top" | "bottom" | "start" | "end" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "start-top" | "start-bottom" | "end-top" | "end-bottom"default "bottom-start"

    Placement relative to the trigger: a side, then optionally the edge to align with (start / end follow the text direction). A submenu opens beside its item, or in its place (submenuPresentation).

  • offsettype numberdefault 0

    Gap between the trigger and the menu, in px (a split button's menu sits 4px away).

  • containerPaddingtype numberdefault 12

    The least space kept between the menu and the window's edges (or the portalContainer's), in px. A split button passes 0, so its menu lines up with the trailing button even at the edge of the screen.

  • presentationtype "popover" | "sheet" | "auto"default "popover"

    Where the menu opens. popover: anchored to its trigger. sheet: in a modal bottom sheet. auto: a sheet on compact windows (below 600px wide) and a popover on larger ones (M3: "Consider adapting menus into bottom sheets on small screens"). Set it on the root menu.

  • submenuPresentationtype "replace" | "beside"default "beside"

    Where a submenu shows in a popover. beside: in a popover of its own next to its item, without covering it (M3: "Submenus should open next to the parent menu item without overlapping it"), for app menus, toolbars and context menus with room. replace: in place of the menu, on the same surface, below a back button and its item's label, for a menu confined to a small surface (a video player's settings, a card, a narrow panel). The surface keeps its corner and its side of the trigger, and its height follows each page. replace extends M3, which shows submenus beside their item. Set it on the root menu; a bottom sheet always shows submenus in place.

  • submenuTransitiontype "fade" | "slide"default "fade"

    How a submenu shown in place (submenuPresentation="replace", or in a sheet) and the page it leaves change. fade: the page going out goes at once and the one coming in fades in. slide: M3's forward and backward pattern, the page coming in sliding 30px in from the end edge going forward and from the start edge going back (mirrored in right-to-left) as it fades in. Under reduced motion only the fade stays; instant drops both in a popover (a sheet has no instant: its pages always change with the transition). Set it on the root menu.

  • afterSelecttype "close" | "back"default "close"

    On a submenu's Menu (inside a SubmenuTrigger): what follows a choice on it, by press or Enter, in a single-select submenu or a single-choice MenuGroup of it. close: the whole menu closes, as in any single-select menu. back: only this submenu closes, so the page that opened it shows again (shown in place) or stays (beside), showing the new choice, with focus on the item that opened it; for a settings page whose choice is all it's for. Space keeps the submenu open either way, a toggle in a multi-select submenu never closes it, and an action (a plain item) still closes the whole menu.

  • portalContainertype Element | null

    The element the menu's popover opens in, instead of body: a video player, so the menu opens over the picture, moves with the player and shows with it in full screen, opened before or after. The menu is placed against its trigger as before, then kept inside the element: containerPadding from its edges, flipping, shifting and capping its height (the list scrolls) within it, and placed again when the element resizes. It keeps the theme, ThemeScope, density and direction of where it's declared. Give the element position: relative, keep the trigger inside it or along its edge, and pass the element from a callback ref kept in state. It must draw its children (not a <video>, <canvas> or <img>). Submenus beside the menu are kept within it as far as they can shift: in an element too narrow for one on either side of the menu, a submenu runs past its edge, so use submenuPresentation="replace" for a small element. Popovers only: a bottom sheet opens over the window (and inside the element in full screen, as every overlay does). The page's body or <html> counts as no element: the menu opens in body, kept in the window. Set it on the root menu.

  • backIcontype ReactElement<unknown, string | JSXElementConstructor<any>>default Material Symbols arrow_back, mirrored in right-to-left

    The icon of the back button above a submenu shown in place of its menu. Set it on the root menu.

  • instanttype booleandefault false

    Open and close with no motion (M3: "In dense products, such as on desktop, menus can open instantly to reduce motion"), and change pages shown in place with none. Submenus follow their root menu. Popovers only: a menu shown as a bottom sheet (presentation="sheet", or auto on a compact window) keeps the sheet's slide, as M3's and Compose's modal bottom sheets always animate; under reduced motion it fades instead.

  • reftype Ref<HTMLDivElement>

    Ref to the menu's list, the role="menu" element, in a popover or a sheet.

Text

  • labelstype Partial<MenuLabels>

    Words the menu shows above a submenu shown in place (in a sheet, or with submenuPresentation="replace"). Set them on the root menu. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

MenuItem 14 props

  • childrentype ReactNodeRequired

    The label.

  • textValuetype string

    Plain-text label for typeahead when children is not a string.

  • leadingIcontype ReactNode

    Icon before the label.

  • selectedIcontype ReactNode

    Icon shown while selected (defaults to a check in selectable menus).

  • descriptiontype ReactNode

    Second line of text (supporting text), read as part of the item's name after the label.

  • badgetype ReactNode

    A badge before the trailing text or icon (M3 anatomy), such as a Badge with a count. It's read after the name, as the item's description.

  • shortcuttype string

    Keyboard shortcut shown at the end, e.g. "⌘C", read as the item's description.

  • trailingIcontype ReactNode

    Icon at the end (an item with a submenu shows an arrow by default).

  • hreftype string

    Makes the item a link: a real <a> with the item's look, role and keys, so the browser's link menu (open in a new tab, copy or save the link) and modified clicks work. A press, Enter or Space follows it, through a RouterProvider (such as NextRouterProvider) on a plain click, and closes the menu. A disabled item, or one that opens a submenu, isn't a link.

  • targettype string

    A link item's target; _blank adds rel="noopener noreferrer" unless rel is given.

  • reltype string

    A link item's rel, e.g. "nofollow".

  • downloadtype string | boolean

    Downloads the link item's file instead of opening it (optionally with a file name).

Text

  • aria-labeltype string

    Accessible name when the label isn't plain text.

MenuGroup 8 props

  • childrentype ReactElement<unknown, string | JSXElementConstructor<any>> | ReactElement<unknown, string | JSXElementConstructor<any>>[]Required

    MenuItems and SubmenuTriggers.

  • titletype ReactNode

    Group label shown above its items.

  • selectionModetype "none" | "single" | "multiple"default the menu's selectionMode

    A group of choices with a selection of its own, beside the menu's other items: its items are radio items (single) or checkbox items (multiple), whatever the menu's own selectionMode, and choosing one never changes another group's. Closing follows the group's mode, as a whole menu's would: a choice closes the menu (Space keeps it open), a toggle keeps it open. none makes the group's items plain actions that close the menu, in a selectable menu too.

  • selectedKeystype Iterable<Key> | "all"

    The group's selected keys (controlled), with selectionMode; 'all' is all its items.

  • defaultSelectedKeystype Iterable<Key> | "all"

    The group's keys selected at first (uncontrolled), with selectionMode.

  • deselectabletype booleandefault true

    With selectionMode: the group's last selected item can be deselected, leaving none. false keeps one of its items selected.

Events

  • onSelectionChangetype ((keys: Selection) => void)

    Called with the group's selected keys, its own only, when they change.

Text

  • aria-labeltype string

    Accessible name for the group when it has no title.

MenuTrigger 4 props

  • childrentype ReactNodeRequired

    The trigger (a Button, IconButton, …) followed by the Menu.

  • opentype boolean

    Whether the menu is open (controlled).

  • defaultOpentype booleandefault false

    Whether the menu starts open, when uncontrolled.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the menu opens or closes.

SubmenuTrigger 2 props

  • childrentype [ReactElement<MenuItemProps, string | JSXElementConstructor<any>>, ReactElement<MenuProps, string | JSXElementConstructor<any>>]Required

    The MenuItem that opens the submenu, then the submenu's Menu.

  • openDelaytype numberdefault 200

    How long (ms) the pointer rests on the item before the submenu opens.

ContextMenuTrigger 5 props

  • childrentype ReactNodeRequired

    The content the menu belongs to, followed by the Menu.

  • opentype boolean

    Whether the menu is open (controlled).

  • defaultOpentype booleandefault false

    Whether the menu starts open, when uncontrolled.

  • disabledtype booleandefault false

    Ignore secondary clicks and long presses.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the menu opens or closes.

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.

Menu tokens (md-comp-menus)
VariableDefaultPaintsCompose
--md-comp-menus-container-elevationvar(--md-sys-elevation-level-2)The menu's shadow (each group's, in the gap layout).MenuTokens.ContainerElevation
--md-comp-menus-container-shapevar(--md-sys-shape-corner-large)The menu's outer corners at rest.MenuTokens.ContainerShape
Standard (variant)
--md-comp-menus-standard-container-colorvar(--md-sys-color-surface-container-low)The menu (each group, in the gap layout).StandardMenuTokens.ContainerColor
--md-comp-menus-standard-menu-item-label-text-colorvar(--md-sys-color-on-surface)An item’s label.StandardMenuTokens.ItemLabelTextColor
--md-comp-menus-standard-menu-item-leading-icon-colorvar(--md-sys-color-on-surface-variant)An item’s leading icon.StandardMenuTokens.ItemLeadingIconColor
--md-comp-menus-standard-menu-item-trailing-icon-colorvar(--md-sys-color-on-surface-variant)An item’s trailing icon, keyboard shortcut or trailing text.StandardMenuTokens.ItemTrailingIconColor
--md-comp-menus-standard-menu-item-selected-container-colorvar(--md-sys-color-tertiary-container)A selected item.StandardMenuTokens.ItemSelectedContainerColor
--md-comp-menus-standard-menu-item-selected-label-text-colorvar(--md-sys-color-on-tertiary-container)A selected item’s label.StandardMenuTokens.ItemSelectedLabelTextColor

Spec status

Built to the M3 Expressive 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.

  • Vertical menu with divider

    Built

    Variant · Layouts, Basic

  • Vertical menu with gap

    Built

    Variant · Layouts

  • Color: standard

    Built

    Configuration · Basic, Layouts

  • Color: vibrant

    Built

    Configuration · Selection

  • Layout: standard

    Built

    Configuration · Selection

  • Layout: grouped

    Built

    Configuration · Basic, Layouts

  • Selection states

    Built

    Use case · Selection

  • Submenus

    Built

    Use case · Submenu

  • Context menu

    Built

    Use case · Context

  • Bottom sheet on small screens

    Built

    Use case · Sheet

  • Density (web)

    Built

    Configuration · Density

  • Gaps on the web

    Extension

    The spec says gaps aren't available on the web yet; layout="gap" offers them, and a gap menu that has to scroll switches to dividers, as the spec asks.

  • Offset

    Extension

    offset sets a gap between the trigger and the menu (the split button uses 4px).

  • Submenus in place

    Extension

    The spec opens a submenu next to its item, without covering it. submenuPresentation="replace" shows it in place of the menu instead, on the same surface below a back button, for a menu confined to a small surface such as a video player; submenuTransition fades or slides the pages, and afterSelect="back" returns to the page that opened a submenu after a choice.

  • Opening inside an element

    Extension

    portalContainer opens the menu inside an element (a player) instead of the page, kept within it and shown with it in full screen.

  • Baseline menu

    Not built

    The spec keeps the square-cornered baseline menu available, but the M3 Expressive vertical menu replaces it here.

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.

  • Menu, MenuItem, MenuGroup, SubmenuTrigger: 38.6 kB
  • MenuTrigger, ContextMenuTrigger: 2.1 kB

M3 Expressive specs

Elevation
level2

Differences from Compose

  • The Expressive grouped menu (Compose's Menu.kt) is the gap layout: each group is its own surface at elevation 2, 2px apart; loose items form implicit groups. The default divider layout follows the M3 spec for the web.
  • Items follow the M3 Menu token files rather than Compose's code: labels are body-large, with 16px of padding at each side, a 12px gap after the leading icon and label-small trailing text (the shortcut). Compose draws label-large labels with 12px of padding and an 8px gap on touch. Select's and Autocomplete's option lists share these items. Group headings start in line with the items' content, where Compose starts them 12px from the group's edge.
  • Submenus aren't in Compose. While one is open, the focused menu takes 24px corners and the other 8px (the SegmentedMenu active and inactive shapes), as the M3 spec describes. Shown in place (submenuPresentation), only one page shows, so the surface keeps its resting corner.
  • The menu is revealed along one axis from its anchored edge as it fades in, instead of Compose's uniform 80% scale, which the M3 motion spec avoids.
  • standard uses surface-container-low and selects with tertiary-container; vibrant is tertiary-container with icons turning tertiary on interaction and selects with tertiary.
  • In a selectable menu an item with no leading icon grows a check in (grid 0fr → 1fr) when selected, as in Compose.
  • placement defaults to bottom-start with no offset; because React Aria resolves start / end from its locale, the menu converts them to physical sides from the trigger's computed direction.
  • A focus fix cancels the trigger's follow-up mousedown so focus stays inside the menu after a mouse open.