Skip to content

[menu] Add Menu v2 based on Base UI - #48823

Draft
LukasTy wants to merge 395 commits into
mui:masterfrom
LukasTy:menu-rfc-playground
Draft

LukasTy wants to merge 395 commits into
mui:masterfrom
LukasTy:menu-rfc-playground

Conversation

@LukasTy

@LukasTy LukasTy commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Adds Menu v2, an unstable Base UI-backed successor to Material UI Menu, with submenu support. This PR builds on #48663 by @mj12albert. It is not ready for release.

Docs and RFC

Please add API and usage comments on docs/data/material/components/menu2/menu2.md and docs/data/material/migration/upgrade-to-menu-v2/upgrade-to-menu-v2.md in this PR.

Changes since the last review

2d07df256a replaces the single-component API. Review comments before this commit can name props and classes that no longer exist.

  • Menu2Trigger replaces the trigger prop and slotProps.trigger. It requires render with an element or a typed callback. Both trigger components now take openOnHover, delay, and closeDelay directly, as in Base UI. The nativeButton prop also belongs on the trigger.
  • All item parts, including submenu triggers, plus groups, labels, and separators support optional render. It changes the element or composes a component while keeping Material styles, theme overrides, and item ripple.
  • These styled parts also support slots.root and slotProps.root. A replacement root takes precedence over render and can omit Material styles. It still receives Base UI behavior props, refs, utility classes, and children. Forward these to preserve behavior and accessibility. A slotProps.root callback receives the owner state: the props and the live Base UI state, or only the props on popups. Items must forward children to keep indicators and, with render, ripple.
  • Menu2 and Menu2Submenu render no element and accept only open-state and behavior props.
  • Menu2Popup and Menu2SubmenuPopup take the positioning, portal, transition, elevation, finalFocus, and slot props.
  • The popup root slot is now the menu surface, which was the paper slot. The stacking layer, which was the root slot, is now portal.
  • MuiMenu2 and MuiMenu2Submenu support only defaultProps. Popup styles move to MuiMenu2Popup and MuiMenu2SubmenuPopup. MuiMenu2Trigger is a new key that supports only defaultProps.
  • c6c5ed3e7b registers the MuiMenu2* theme types by default and removes the Unstable_Menu2/themeAugmentation entry point.
  • 4fb0a872d0 removes detached triggers.
  • 0a25dc1f9a moves modality to Material UI. Menu2 passes modal={false} to Base UI and locks page scroll through ModalManager. Touch opens also lock, and a second trigger click closes the menu with reason outside-press.
  • 282c6b7ca7 fixes the Dialog issues from the interop review:
    • A modal menu blocks outside clicks with an internal layer, as Base UI does. The layer has no slot, class, or theme key. The backdrop slot is now a visual layer only: it renders only when configured and lets clicks through. slots.backdrop={null} removes only the visual layer. Use modal={false} to let outside clicks through.
    • An outside press keeps focus off the page body. A Dialog's FocusTrap then cannot take focus before Base UI returns it to the trigger.
    • An item press that closes the menu focuses the trigger first. A Dialog that the item opens then returns focus to the trigger. The docs keep the disableRestoreFocus workaround only for closeOnClick={false}, a menu without Menu2Trigger, and a custom finalFocus.
    • An explicit finalFocus ref or function applies only when focus is on the page body or in the menu tree. Base UI applies it in all cases, so it can take focus from a Dialog field.
    • The upgrade guide documents positionMethod="fixed" on every popup level for a container inside a Dialog. Plain Base UI needs the same setting.
  • 9cf9c434e9 replaces slots.indicatorIcon and slotProps.indicatorIcon with icon and checkedIcon props on Menu2CheckboxItem and Menu2RadioItem, as in Checkbox and Radio. Theme defaultProps can set them. The icon keeps the indicatorIcon class and styleOverrides.indicatorIcon, and defaults to the small size.
  • cc7d36c9c5 adds startAdornment, endAdornment, and inset to all item parts. They replace ListItemIcon, ListItemText, and a shortcut Typography in the children: <MenuItem startAdornment={<ContentCut fontSize="small" />} endAdornment="Ctrl+X">Cut</MenuItem>. inset keeps an empty start column, so a text-only label aligns with the labels of items that have a start adornment. Alignment is opt-in. Each part gets startAdornment, endAdornment, and inset classes and theme keys; MuiMenu2Item keys apply to all parts.
  • 409a99b4ac removes dense. Menu2 has no dense mode. The popup List sets dense={false}, so slotProps.list, the MuiList theme default, and an outer dense List do not change Menu2.
  • 76534146a3 removes the code that Menu2 shared with the classic Menu. Menu2ItemBase has its own copy of the item styles. The classic Menu and MenuItem are the same as on master. The rendered styles do not change.
  • 9499cea4b1 aligns inset separators and group labels with the item labels. An inset Menu2Separator uses 52px in every position. An inset Menu2GroupLabel uses 52px, or 36px with disableGutters.
  • 0317ba4900 removes the classic child composition styles. Items no longer restyle ListItemIcon, ListItemText, or a plain Divider, and they no longer provide a ListContext. These children render with their List styles. Use startAdornment, endAdornment, inset, and Menu2Separator.
  • 7a793d8033 and ee12bae260 make the slot prop types strict. Unknown keys in the object form are type errors. data-* keys need the DataAttributesOverrides augmentation, as on the other components.
  • 236247c044 passes the Base UI state as is to the item render functions, as the groups, labels, and separators already do. divider, disableGutters, and inset stay in ownerState. Each part exports a Menu2*State alias for its render state.
  • fcb588ec25 adds render to Menu2Popup and Menu2SubmenuPopup for the menu surface. It keeps the Paper, theme, and sx styles, and slots.root takes precedence. slotProps.root no longer accepts component.
  • 12a3e08ce8 replaces component with render on slotProps.list and on slotProps.indicator of the checkbox, radio, and submenu trigger items. render keeps the slot styles, and slots.<slot> takes precedence. A render function gets the Base UI state of its part.
  • 7a75b571e8 adds render to slotProps.portal, slotProps.positioner, and slotProps.backdrop with the same rule. No part or slot takes component.
  • e62520a035 types the slotProps and theme callbacks as their runtime value. They receive the props and the live Base UI state, such as highlighted. Popup callbacks receive only the props. MuiMenu2Item also styles the link, checkbox, radio, and submenu trigger items, so its disabled and open fields are optional.
  • 31bea1fab3 reads the aria-label of a render element on Menu2Popup and Menu2SubmenuPopup, and the id of a slotProps.portal.render element, as Base UI does. Before, the trigger stayed the menu name, and aria-owns pointed to a missing ID. Menu2GroupLabel also registers the id of its render element, so the group keeps its name. 49aefe75db also reads the element aria-label when the aria-label prop is undefined.
  • fa98657248 keeps the focus that onOpenChange moves out of the menu on an item press, as Base UI does. Before, Menu2 moved it to the trigger. The Dialog handoff does not change.
  • e571095599 resolves the MuiDivider variant and the MuiListSubheader inset in Menu2Separator and Menu2GroupLabel. An inset from these theme defaults now lines up with the Menu2 items, and the owner state shows the resolved values.
  • 4a2609702e states that a Menu v2 menu takes only Menu v2 parts. A classic MenuItem throws inside MenuPopup, also through render. Other classic components render, but Base UI does not register them as items, so arrow keys and typeahead skip them. Other components compose through render on a part. The upgrade guide, the Menu v2 page, and the RFC state the rule, and the customized demo uses startAdornment.
  • 4a3b07912d states that on React 17, a Menu2Trigger with openOnHover needs a unique id from the first render. An id that an effect sets later, such as one from unstable_useId, does not work. The Menu v2 page also says that a classic MenuItem throws through render. The RFC bundle table adds a classic Menu + unstable_enhanceDensity case (+234 B gzip) and uses the merge base 9769f52fee.
  • 318ec33a9a fixes the React 17 runs. The AccountMenu2 and PositionedMenu2 regression demos now need React 18 for React.useId, and the e2e Account menu uses a static trigger id. The commit removes the e2e DocsLayout tests, because Stack now uses CSS gap, so the fixed focus guards cannot move the trigger. Upgrade step 7 now says to copy the theme keys, and to keep MuiMenu and MuiMenuItem for Select, TablePagination, and the classic Menu. The RFC adds the theme types as open question 3.

Scope

  • Public @mui/material/Unstable_Menu2* entry points for 14 components. The classic Menu API does not change.
  • Explicit Root/Trigger/Popup composition. Menu2 controls behavior and renders no element. Menu2Trigger merges behavior into the element supplied through render. Menu2Popup owns the menu surface, positioning, portal, and transition. Submenus use the same three parts. Menu2Submenu renders no element, and Menu2SubmenuPopup owns the submenu surface. Unlike Menu2Trigger, Menu2SubmenuTrigger renders its own menu item, and its children are the item content.
  • Plain, link, checkbox, and radio items, with radio groups, groups, group labels, and separators. Link items have no disabled state, as in Base UI. Detached triggers are outside this release.
  • Context menus are outside this release. The Context menus section of the upgrade guide tells users to keep the classic Menu.
  • Menu2 has no dense mode. Items do not take dense, and the popup list ignores it.
  • Menu2 reuses no code from the classic Menu, MenuList, or MenuItem.
  • Popup styles use MuiMenu2Popup and MuiMenu2SubmenuPopup; Menu2 item theme keys remain unchanged. Popup refs, sx, and HTML props target the menu surface. The renderless Menu2 and Menu2Submenu support behavioral defaultProps, but no slots or DOM styling. Style the element supplied to Menu2Trigger directly.
  • Grow is the default transition and follows theme.motion.reducedMotion. Other compatible Material transitions and CSS animations remain available.
  • Generated PropTypes and API references cover all public components. Rendered parts have conformance tests; renderless roots have behavior tests.
  • Material UI supports TypeScript 5 and later (#49323). Standard theme types include all MuiMenu2* entries; no augmentation import is needed.
  • @mui/material adds @base-ui/react ^1.9.0 as a direct dependency. Version 1.9.0 includes the menu tree fix and the retained-popup transition fix. No local Base UI patch is included.

Changes outside Menu2

These changes affect existing components. Please review them separately.

  • ModalManager adds an internal lockScroll(container) method, and useModal exports its shared instance for Menu2. A Menu2 and a Modal on one page share one scroll lock, so Base UI and Material UI no longer write the same styles. With no Menu2 open, ModalManager runs the master code. The public @mui/material/Modal exports do not change.
  • The internal RadioButtonIcon merges a className prop into its root, so Menu2RadioItem can add the indicatorIcon class. Radio does not pass className, so its output does not change.
  • enhanceHighContrast adds forced-colors overrides for the MuiMenu2* items, including the end adornment.
  • unstable_enhanceDensity adds rules for the Menu2 items and indicators, as the note on #48749 asks, and for the group labels and inset separators. At every density, the Menu2 items match the classic MenuItem height and text start.
  • vitest.shared.mts inlines @base-ui/react and @base-ui/utils in the jsdom tests on React 17. Their ESM files import react/jsx-runtime without an extension, and Node cannot resolve that import for React 17.
  • @mui/material/styles exports ComponentsOwnerStateList. Theme variants and style overrides read ownerState from it. It extends ComponentsPropsList. The Menu2 item, radio group, and separator keys also include the resolved owner state, such as highlighted.
  • API tooling resolves components with only a subpath export. It lists a package-root import only when that export exists. The undocumented-prop check uses the same lookup to skip React DOM props. This removes incorrect @mui/material imports from the PigmentContainer, PigmentGrid, and PigmentStack API pages. PigmentContainer also lists its MuiContainer classes. typescript-to-proptypes preserves null in React element-type unions.
  • The focus-visible customization demo adds a Menu2Item row, so its regression screenshot changes.
  • The jsdom test setup delays jsdom 31 focus fixup requests while fake timers are active and runs them after the test restores real timers. Otherwise, a fake clock can stop jsdom animation frames for the rest of the run, and the Menu2 tests that run after the Select tests time out. jsdom does not support this case: Focus fixup can strand the rendering interval after fake timers are restored jsdom/jsdom#4455. The Firefox override of focus() in the browser test setup now reads the focus options before it calls the native method without arguments. Base UI checks preventScroll support through these options, and without the read it does not return focus after an outside press.

Before release

  • Review the explicit composition API and the visual changes.
  • Repeat manual screen-reader checks for this composition. The RFC checklist covers trigger announcements, keyboard opening, Escape, and Tab.
  • Review the axe exceptions in menus.a11y.json. In the non-modal fixture, axe reports an aria-hidden-focus failure for the Base UI focus guards. The open and nested fixtures report this rule as incomplete. Since axe-core 4.14.1, aria-valid-attr-value passes in all three fixtures. The fixtures skip assertions only for aria-hidden-focus.
  • Review the known issues. Two are Base UI limitations: item activation during exit (#5519) and container refs read before mount. For an initially unresolved portal container, pass callback-ref state to container on Menu2Popup. The others are Material UI integration gaps and API limits, for example: ModalManager can hide a retained popup inside a kept-mounted Dialog. With the default portal container, leave keepMounted disabled on Menu2Popup inside a kept-mounted Dialog. Menu2 also has the known limits of the Modal scroll lock, the same as Dialog: no lock when html scrolls the viewport, and an old body overflow value restored when other code changes it while the menu is open. A separate change can fix both for every Modal. A Dialog with disableScrollLock also blocks the lock of a Menu2 above it, or keeps the lock of a Menu2 below it until the Dialog closes. [modal] Fix the scroll lock of stacked modals with disableScrollLock #49915 fixes this for every Modal. A container inside a positioned element that clips its overflow, such as the Dialog paper, clips the menu. Set positionMethod="fixed" on Menu2Popup and on each Menu2SubmenuPopup.
  • Cherry-pick the PR into v9.x after the merge. The upgrade guide and the Menu v2 page name v9.7 as the first release. If v9.7 does not include the cherry-pick, change the version on both pages.
  • Add the RFC known issues that the user docs do not cover yet, for example the scroll lock limits.
  • Run the nightly CircleCI workflow on the PR. It runs React 17, React 18, and React next, which PR CI does not run. A local run of the Menu2 tests on React 17 and 18 passes.
  • Keep docs and generated references aligned, then repeat validation on the release revision. See the hosted release plan.

Open questions for the team

The RFC open questions list the gains, costs, and alternative for each question:

  1. render state shape: render receives the unchanged Base UI state, and the Material props are only in ownerState. Should render receive ownerState instead?
  2. Classic theme keys: Menu2 parts render classic components, such as Divider and Paper, so the theme keys of these components also reach Menu2. Should the Menu2 parts stay open to these keys, or separate from them?
  3. Theme types: the standard theme types include the MuiMenu2* entries, so each TypeScript program that imports Material UI loads about 150 more declaration files. Should we keep this, or restore the opt-in Unstable_Menu2/themeAugmentation import?

Known limitations and follow-ups

The RFC known issues list the user-facing limits. These items are for reviewers:

  • Base UI internals: Menu2 reads the undocumented data-rootownerid attribute, sets data-base-ui-inert, and has three focus workarounds that depend on Base UI 1.9.0 timing. At 03543cfbd2, 6 Menu2 tests failed on the build of [popups] Keep closing popups out of the a11y tree and focus order base-ui#5537. Run the Menu2 tests on each Base UI upgrade.
  • Base UI group label IDs: Menu.GroupLabel registers its generated ID, not the ID of a render element, so plain Base UI leaves the group unnamed. Menu2GroupLabel works around it for the element form. [accordion][combobox][dialog][field][fieldset][menu][meter][popover][progress][select][slider][tabs][toast] Register the rendered id of labels, titles, and descriptions base-ui#6358 fixes it in Base UI. Remove the workaround after the upgrade to the next Base UI release.
  • Base UI on React 17: a Menu2Trigger with openOnHover and no id does not open on hover (RFC known issue). [menu][popover] Keep the trigger mounted on React 17 base-ui#6359 (draft) fixes it in Base UI. The docs tell users to set an id from the first render, and the tests set a static trigger id.
  • Portal render functions: a slotProps.portal.render function that sets its own id leaves aria-owns on a missing ID. Plain Base UI reads the ID from the returned element. Use slotProps.portal.id or a render element.
  • API pages: the generated API pages list highlighted for the five item parts and root for Menu2Trigger as rule names. The theme types reject these keys, and the runtime ignores them. [docs-infra] Hide rule names that are not styleOverrides keys #49778 hides these rule names.
  • Slot callback types: TypeScript does not run excess property checks on the object that a slotProps callback returns, so unknown keys and component pass. This is a TypeScript limit, also without WithDataAttributes, so classic components have the same gap. Menu2 also has no Menu2*SlotPropsOverrides interfaces.
  • Submenu without a trigger: Menu2Submenu does not warn in development when it has no Menu2SubmenuTrigger. A plain Menu2Item in its place does not open the submenu. Base UI does not warn either.
  • Popup list: the popup list still renders the Material List, and slotProps.list takes ListProps without dense. A follow-up can replace List, and that change also changes the slotProps.list API.
  • Select and TablePagination: both still render the classic Menu, and their move to Menu2 is a separate decision. Upgrade step 7 tells apps to keep the MuiMenu and MuiMenuItem theme keys for these components.

Experiments

  • Playground -- classic Menu comparison, controlled anchors, behavior, positioning, transitions, and reduced motion.
  • Recipes -- Tooltip descriptions, Menu and Menu2 inside Dialog, and opening Dialog from a menu.

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+4.34KB(+0.76%) 🔺+785B(+0.48%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±10.3% (±20.7% at worst) · ran 3m 44s · details


Check out the code infra dashboard for more information about this PR.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 20, 2026
@LukasTy LukasTy added type: new feature Expand the scope of the product to solve a new problem. scope: menu Changes related to the menu. RFC Request For Comments. labels Jul 22, 2026
@LukasTy LukasTy self-assigned this Jul 22, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 22, 2026
@LukasTy
LukasTy force-pushed the menu-rfc-playground branch from b8d5972 to 905a982 Compare July 22, 2026 14:13
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Jul 27, 2026
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Aug 12, 2026
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Aug 21, 2026
@aarongarciah

Copy link
Copy Markdown
Member

Nice work @LukasTy. Some comments/questions:

Open questions

1. Context menu: does it need its own component?

I’m inclined to ship a separate component, as Base UI's ContextMenu gives us touch long-press.

2. Accessibility: what is still ours

IMO existing color contrast problems should be fixed globally and not per component i.e. I assume the problematic interactive states without 3:1 contrast are present in other parts of the library.

3. Other defaults

These seem fine, as they’re Base UI’s defaults.

4. SSR, 'use client', ref typing

Is there a benefit narrowing the refs' types? If so, could we narrow the refs per part and type component through OverridableComponent like the rest of the library?

5. How much Base UI shows through

I think a facade makes more sense as we can be able to filter out certain non-supported features (e.g. detached triggers?). Today, Menu2Props inherits handle, triggerId, defaultTriggerId and orientation from Menu.Root, and handle can't even be used without Menu.createHandle.

6. The tint of an open submenu parent

Same comment as point number 2. Is this problem present in other existing components? If so, it’s good to have it into account but in case it informs the API, but if it’s something to be fixed at a global level I wouldn’t tackle in this component if it deviates from the rest of the library.

7. The collapsed trigger API duplicates the Base UI item registration

Q: Is there intention to support detached triggers? Is there intention to ship a Menubar component?

Fable 5.1 came up with this:

Public API delta. trigger keeps its name and type at both levels. Hover props become real props. slotProps.trigger shrinks from Record<string, any> to one typed key. DOM output, class hooks (MuiMenu2SubmenuTrigger-*), keyboard behavior: unchanged.

// before
interface Menu2SubmenuProps {
  trigger?: React.ReactElement;
  slotProps?: { trigger?: Record<string, any>; paper?: ...; list?: ... };
}
interface Menu2Props {
  trigger?: React.ReactElement;
  slotProps?: { trigger?: Record<string, any>; paper?: ...; list?: ... };
}

// after
interface Menu2SubmenuProps {
  trigger?: React.ReactElement;   // a Menu2 item, optionally wrapped (Tooltip etc.)
  openOnHover?: boolean;          // default true
  delay?: number;                 // default 100
  closeDelay?: number;            // default 0
  slotProps?: { paper?: ...; list?: ... };   // no trigger slot
}
interface Menu2Props {
  trigger?: React.ReactElement;   // any element, behavior merged in (unchanged)
  openOnHover?: boolean;          // default false
  delay?: number;
  closeDelay?: number;
  slotProps?: { trigger?: { nativeButton?: boolean }; paper?: ...; list?: ... };
}

Submenu, common case. Only the hover knobs move.

// before
<Menu2Submenu
  trigger={<Menu2Item>Share <KeyboardArrowRightRoundedIcon fontSize="small" /></Menu2Item>}
  slotProps={{ trigger: { openOnHover: false, delay: 200 } }}
>
  <Menu2Item>Email</Menu2Item>
</Menu2Submenu>

// after
<Menu2Submenu
  trigger={<Menu2Item>Share <KeyboardArrowRightRoundedIcon fontSize="small" /></Menu2Item>}
  openOnHover={false}
  delay={200}
>
  <Menu2Item>Email</Menu2Item>
</Menu2Submenu>

Root trigger. Visual props go on the element, behavior on the menu. Two homes become one.

// before (recipes today)
<Menu2
  trigger={<Button>File</Button>}
  slotProps={{ trigger: { variant: 'contained', endIcon: <KeyboardArrowDownRoundedIcon />, openOnHover: true } }}
>

// after
<Menu2
  trigger={<Button variant="contained" endIcon={<KeyboardArrowDownRoundedIcon />}>File</Button>}
  openOnHover
>

Custom wrapper around a submenu trigger. This is the user-facing win of the internals change.

// before: the wrapper must forward every prop Base UI merges in, plus the ref,
// or the item silently stops being a submenu trigger (recipes' MenuTooltip)
const MenuTooltip = React.forwardRef(function MenuTooltip({ title, children, ...forwarded }, ref) {
  return (
    <Tooltip title={title} describeChild>
      {React.cloneElement(children, { ...forwarded, ref })}
    </Tooltip>
  );
});

// after: nothing travels through the wrapper, the item renders the Base UI trigger itself
function MenuTooltip({ title, children }) {
  return <Tooltip title={title} describeChild>{children}</Tooltip>;
}

<Menu2Submenu trigger={<MenuTooltip title="Open view settings"><Menu2Item>View</Menu2Item></MenuTooltip>}>

Root level keeps the old contract (Button isn't menu-aware), same as Tooltip's children today.

Theme defaults. Typed now.

// before: allowed, but `trigger` is Record<string, any>, so no autocomplete, typos pass
MuiMenu2Submenu: { defaultProps: { slotProps: { trigger: { openOnHover: false } } } }

// after
MuiMenu2Submenu: { defaultProps: { openOnHover: false, delay: 150 } }

What stops working, all with a dev warning

  • Non-Menu2 element as submenu trigger. Before: trigger={<ListItemButton>…</ListItemButton>} worked through render merging. After: unsupported. Use <Menu2Item component={…}> or slots.root, which is how you customize the row anyway.
  • Checkbox, radio, link item as submenu parent. Before: worked with the double registration. After: warning. A submenu parent is a plain menuitem in ARIA; Base UI has no checkable submenu trigger either.
  • closeOnClick on the trigger item: ignored. Before it was overridden silently, now it warns.

Internals, for feasibility. Small diff on top of what exists.

// Menu2Submenu: provide, don't wrap
<BaseMenu.SubmenuRoot {...rootProps}>
  <Menu2SubmenuTriggerContext.Provider value={{ openOnHover, delay, closeDelay }}>
    {trigger}
  </Menu2SubmenuTriggerContext.Provider>
  <Menu2SubmenuPopup {...popupProps}>{children}</Menu2SubmenuPopup>
</BaseMenu.SubmenuRoot>

// Menu2Item: switch primitive
const submenu = React.useContext(Menu2SubmenuTriggerContext);
const Primitive = submenu ? BaseMenu.SubmenuTrigger : BaseMenu.Item;
<Primitive
  ref={ref}
  render={/* same ButtonBase root as today */}
  disabled={disabled}
  label={label}
  nativeButton={nativeButton}
  className={(state) => clsx(classes.root, state.highlighted && classes.highlighted,
    submenu && menu2SubmenuTriggerClasses.root, state.open && menu2SubmenuTriggerClasses.open)}
  {...(submenu ? submenu : { closeOnClick })}
  {...other}
/>

Two details to get right: the item re-provides an empty context to its own subtree so nothing leaks, and Menu2Submenu warns in an effect if no item claimed the context (replaces today's warnMenu2TriggerRef at that level). SubmenuTrigger already computes disabled from the root and parent stores, so <Menu2Submenu disabled> keeps working.

Other

  • Q: to achieve RTL we'd bridge theme.direction to Base UI's DirectionProvider, right?
  • Preview card
    • Is this a common pattern?
    • Why a useMenu2ItemPopover hook?
    • Calling it Preview Card is misleading, as someone familiar with Base UI’s PreviewCard could think it’s related. While Base UI’s PreviewCard is purely visual, in this case the preview card is being used to describe the corresponding menu item (via aria-describedby).
    • Preview card decision text still says "no timer and no polling" while the current code polls per frame with a deadline.
  • sx goes to the Paper while className/classes.root go to the popup div (rendering Paper as the popup would give one root).
  • MuiMenu2.styleOverrides doesn't seem to reach submenu surfaces.

@LukasTy

LukasTy commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Thanks for the thorough pass, @aarongarciah. 🙏

Open questions

  1. Context menu: agreed, a separate component. Touch long-press is the deciding feature, and only Base UI's ContextMenu gives it. I will record it as a decision, but I propose keeping it out of scope and do a follow-up based on priority.

  2. Accessibility: agreed. The highlight tint comes from the same style helper the classic MenuItem uses, so the 3:1 gap is inherited, not introduced here. I will reword Q2 to say so and keep parity rather than fix it in one component.

  3. Defaults: Cool, looks like we can close this question.

  4. Ref typing: yes. Narrow the refs per part and type component through OverridableComponent like the rest of the library.

  5. Facade: done. Menu2 and Menu2Submenu now pick the props they forward from Base UI (48b8365), so handle, triggerId, defaultTriggerId, and orientation are gone, each with a spec guard, and a prop that a later Base UI minor adds reaches neither the type nor the DOM. Menu2.slotProps.trigger follows the same rule (88e5ec1). The parts that render an element (items, submenu trigger, popup) still pass HTML attributes through by design, so Q5 stays open only for those.

  6. Open tint: the classic Menu has no submenus, so no existing component carries this state to match. Reusing action.hover was the option that adds no token. Happy to follow whatever design decides globally.
    Main question remains the looks when focusVisible is toggled.
    Do you feel like keeping the same background tint as without focusVisible is the right call?
    Or you have a better idea to be more in line with focusVisible style?

  7. Done, with one deliberate difference. The hover props are real props now: openOnHover, delay, and closeDelay live on Menu2 (88e5ec1) and on Menu2SubmenuTrigger (6eaab95), and theme defaults type them the same way. Menu2.slotProps.trigger shrank to a typed facade with nativeButton, className, and ref; the trigger element owns its visual props, so the recipes now read trigger={<Button variant="contained" endIcon={...}>File</Button>} with openOnHover on the menu. The difference is the submenu side. Instead of a context switch inside Menu2Item, the trigger is the explicit Menu2SubmenuTrigger part, which Menu2Submenu renders as-is. It gives the same wins: nothing travels through a Tooltip wrapper for the menu, and the unsupported cases (a checkable item as a submenu parent, closeOnClick on the trigger) are type errors instead of dev warnings. It also answers your two questions.
    Menubar: yes, it is the ultimate goal, but that's outside the scope and needs a proper prioritization. [MenuBar] Create Material-UI component from the Docs example #48336 came from the Menubar docs page, and a menubar's top-level items are triggers, which the explicit part serves directly.
    Detached triggers: outside the contract today, which is why handle and triggerId are omitted; if they return, the explicit part is the shape that supports them. Q7 in the RFC records both (1e7c8e6).

Other

  • RTL: yes, exactly that. Landed in f0c3ab6: useRtl() -> Base UI DirectionProvider.

  • Preview card. Common: not in our own docs; it exists because the recipes needed a Tooltip and a Popper over items and each repeated the same anchor and aria-describedby wiring.
    Hook rather than component: the recipes need two different surfaces, and a hook keeps the public surface small and is reversible into a component later.
    Naming: agreed, it collides with Base UI's visual PreviewCard while ours is an accessible description. WDYT about useMenu2ItemPopper?
    The stale "no timer and no polling" text: fixed in 1e7c8e6; the wait polls per frame with a 500ms deadline, because Animation.finished never settles for several states.

  • sx vs className: confirmed, two roots. Rendering Paper as the popup is the right fix. I will do it.

  • MuiMenu2.styleOverrides and submenus: intentional today, MuiMenu2Submenu is its own theme key (recorded in the Theme API decision). Open to one key with slots if you would rather match Autocomplete.

@siriwatknp siriwatknp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through the branch with a focus on the Base UI boundary, read the Base UI menu source side by side.

The conformance pilot and the Grow adapter look solid to me.
The keyboard bridge and the explicit Menu2SubmenuTrigger match how Base UI works internally, both are the right calls.

I also tried an alternative for the shared styles: layered nameless styled components instead of exported style objects.
See LukasTy#2, it targets this branch.
It removes the three *Styles modules and the getMenuItemRootStyles(theme, classes, options) signature.
Verified with tsc, eslint, 350 unit tests, and a Pigment CSS transform fixture.
Main open point: the shared base styles the highlight through [data-highlighted], which touches the Mui-* classes contract.
Curious what you think.

Comment thread patches/README.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved
Comment thread docs/pages/experiments/menu2-rfc.md Resolved

@siriwatknp siriwatknp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a styles and visuals pass on the deploy preview (Chrome, real pointer and keyboard input).

Visual parity holds. I measured computed styles on the Classic vs successor section: same elevation 8 shadow, radius, list padding 8px 0, item height 36px with 6px 16px padding, same selected tint rgba(25, 118, 210, 0.08), same disabled opacity 0.38, same popup width. The only differences are the intended ones (div list vs ul, collision-aware max-height).

One behavior issue found, inline comment below.

@LukasTy

LukasTy commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

I also tried an alternative for the shared styles: layered nameless styled components instead of exported style objects.
See LukasTy#2, it targets this branch.
<..>
Curious what you think.

Great idea! 👍
Applied the shared styled-base approach to items, popups, and indicators.
Each component keeps its theme key.
Item highlight styles still use the public Mui-* classes, so this does not change that contract.

LukasTy and others added 11 commits November 24, 2026 18:23
Measure again against the merge base 3d18274. The classic Menu now grows only by the shared ModalManager scroll lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Item render functions now receive the Base UI state of their part, as groups, labels, and separators already do. The Material props stay in ownerState. Each part exports a Menu2*State alias for its render state.

The RFC lists the render state shape as an open question for the team.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Menu2Popup and Menu2SubmenuPopup take render for the menu surface. It keeps the Paper, theme, and sx styles, and slots.root takes precedence. The render function receives the Base UI popup state.

slotProps.root no longer accepts component, so render is the only way to change the surface element.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The slotProps callbacks and the theme callbacks now get the props and the live Base UI state in their types, which matches the runtime owner state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base UI reads the aria-label of a popup render element and the id of a portal render element. Menu2 hides these elements behind its render functions, so it now lifts both. The group label also registers the id of its render element.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An item press close no longer focuses the trigger when onOpenChange moved focus out of the menu tree, as in Base UI. finalFocus shares the same rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
LukasTy and others added 2 commits November 26, 2026 16:38
A classic MenuItem throws inside MenuPopup, and other classic components get no menu behavior. The upgrade guide, menu2.md, and the RFC now state the rule, and the customized demo uses startAdornment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Tell React 17 users to set a trigger id from the first render for openOnHover.
- Say that a classic MenuItem also throws through render, and use a router link as the render example.
- Add a classic Menu + unstable_enhanceDensity case to the bundle script, and measure again against the merge base 9769f52.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +156 to +161
const transitionTimeout =
transitionDuration === 'auto' &&
!(TransitionSlot as (React.ElementType & { muiSupportAuto?: boolean | undefined }) | null)
?.muiSupportAuto
? undefined
: transitionDuration;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason transitionDuration={0} still shows the starting style for one frame?

From what I tested, the first frame after opening has opacity: 0 and scale(0.75, 0.5625), and the menu becomes visible on the next frame.
Classic Menu with the same prop is fully visible on the first frame:

Classic Menu is visible on the first frame, Menu2Popup is not

<Menu2Popup transitionDuration={0}>
  <Menu2Item>One</Menu2Item>
</Menu2Popup>

The docs say "Set transitionDuration={0} to remove the animation." so I'd expect the same result as classic Menu.
slots={{ transition: null }} works fine.

Comment on lines +83 to +86
...(!theme.focusVisible && {
[`&.${buttonBaseClasses.focusVisible}`]: {
backgroundColor: (theme.vars || theme).palette.action.focus,
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs suggest a theme variant for the highlighted state (Shared theme styles), but a variant with backgroundColor has no visible effect:

createTheme({
  components: {
    MuiMenu2Item: {
      styleOverrides: {
        root: {
          variants: [
            { props: { highlighted: true }, style: { backgroundColor: 'pink' } },
          ],
        },
      },
    },
  },
});

With keyboard navigation the item has both Mui-focusVisible and MuiMenu2Item-highlighted, and the background stays action.focus.
&.Mui-focusVisible here has higher specificity than a root-level variant. Adding '&.Mui-focusVisible' inside the variant makes it work (right side):

The highlighted variant has no effect until Mui-focusVisible is added

Maybe use :where() like Menu2SubmenuTriggerRootSlot does, so that the variant wins?

Also, the docs give three ways to style this state: the highlighted variant, .Mui-focusVisible (State data attributes), and .MuiMenu2Item-highlighted in the upgrade guide (focusVisibleClassName row). Please keep one that works and show it as an example.

@@ -396,6 +471,77 @@ export default function enhanceHighContrast<
],
},
},
MuiMenu2Item: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is in scope, but in forced colors the menu popup has no visible edge. The browser removes the shadow, and the popup background is the same Canvas color as the page, so it's hard to see where the menu starts.

Classic Menu and Popover have the same gap, so it's not a regression. Since this PR already adds Menu2 rules here, how about an outline for the popups too?
I tried it as a theme override on top of enhanceHighContrast (right side):

Without and with an outline on the popups in forced colors

Could be something like:

MuiMenu2Popup: {
  ...c?.MuiMenu2Popup,
  styleOverrides: {
    ...c?.MuiMenu2Popup?.styleOverrides,
    root: [
      c?.MuiMenu2Popup?.styleOverrides?.root,
      { [HCM]: { outline: `1px solid ${hcTokens.buttonBorder}` } },
    ],
  },
},

and the same for MuiMenu2SubmenuPopup.

The examples use local names such as `Menu` and `MenuItem`.
The import paths, theme keys, and CSS classes keep their `Menu2` names.

Build each menu only from these parts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menu v2 doesn't cover filtering (Menu.FilterProvider, Menu.Input, Menu.List, Menu.Empty) from @base-ui/react 1.9.0.
I think it's fine to leave it out since it's still a preview in Base UI, just noting it for later.

For reference, a text field inside MenuPopup doesn't work today because typeahead takes the typed characters. The Base UI parts do work inside MenuPopup from what I tested, but the input is unstyled.

| :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `autoFocus` | Delete it. |
| `dense` | Delete it. Menu v2 has no dense mode. |
| `selected` | For one current value, use `MenuRadioItem` inside a `MenuRadioGroup`, and add `closeOnClick` to close the menu on selection. For independent toggles, use `MenuCheckboxItem`. See [Update the items](#6-update-the-items). |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention that radio items add an indicator column. From what I tested, following this row on a classic menu with icons gives two leading icons per item (radio + icon), and the label moves from 52px to 88px:

classic, migrated per this row, icon used as the indicator

Using the icon as the indicator keeps the layout, maybe worth showing here:

<MenuRadioItem value="copy" icon={<ContentCopy />} checkedIcon={<ContentCopy />}>
  Copy
</MenuRadioItem>

Also, the role changes from menuitem to menuitemradio. It's an improvement, but screen readers announce it differently, so please mention it in this row too.

## Max height menu

The menu limits its height to the viewport and to the space available at the anchor, and scrolls its content.
To set a smaller limit with the `sx` prop on `MenuPopup`, use `min(320px, var(--available-height))` to keep it within short screens.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching the popup width to the trigger is a common customization (select-like menus, split buttons), so I think it needs a demo.
From what I tested, --anchor-width already works but the docs don't mention it:

default width vs minWidth: var(--anchor-width)

<MenuPopup sx={{ minWidth: 'var(--anchor-width)' }}>

It also keeps matching when the trigger resizes:

popup width follows the trigger on resize

var(--available-height) here is also the only popup CSS variable the docs mention. Please list the others with the demo, like Base UI's Positioner CSS Variables: --anchor-width, --anchor-height, --available-width, --available-height, --transform-origin.

- Give `MenuPopup` an accessible name with `aria-label` or `aria-labelledby`.
- Pass `finalFocus` to `MenuPopup` to return focus to the element when the menu closes. Otherwise, focus can move to an unrelated element. `finalFocus` does not move focus from an element outside the menu, for example from a field in a Dialog that an item opens.

This wiring does not provide the keyboard behavior of `MenuTrigger`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected that Tab doesn't close a menu without a trigger? From what I tested, focus goes to a hidden focus guard, then the page body, then the anchor button, and the menu stays open the whole time (left: without a trigger, right: with MenuTrigger):

without a trigger vs with MenuTrigger

With MenuTrigger, and with the classic Menu that this section compares to (anchorEl), Tab closes the menu. Plain Base UI without a trigger behaves the same as Menu2, so it comes from Base UI.
Since Menu2 already owns the modal layer, maybe it can close on focus out here too. Otherwise, please mention it in this section next to the other keyboard differences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up: plain Base UI with a detached trigger (Menu.createHandle) closes on Tab as expected. So the gap here comes from Menu2 not supporting handles yet, and this section is the only way to anchor to an outside element.
Maybe point to MenuTrigger first in this section, since it works anywhere inside Menu, and keep this pattern for anchors that can't be a trigger.

// The popup has no full-screen Modal. Limit its height to the viewport
// and the space available at the anchor, not to its parent's height.
maxHeight: 'min(calc(100vh - 96px), var(--available-height))',
overflowY: 'auto',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a scrolling menu, Home and End hide the list padding. From what I tested, Home leaves scrollTop at 8 and End stops 8px short, so the first and last items touch the popup edge. The classic Menu keeps the padding visible:

classic vs Menu2 after Home and End

Is it worth matching classic here? scrollPaddingBlock: 8 on this root fixes it from what I tested, but it repeats the list padding value, so I'm also fine leaving it to users with sx.

- Run the AccountMenu2 and PositionedMenu2 regression demos only on React 18 and later. These demos call React.useId.
- Give the e2e Account menu fixture a static trigger id. Remove the DocsLayout fixture and its tests: Stack now uses CSS gap, and the focus guards use fixed positions, so the trigger cannot move.
- Upgrade guide step 7: copy the theme keys, and keep MuiMenu and MuiMenuItem while the app uses Select, TablePagination, or a classic Menu.
- RFC: add the theme types as open question 3, and remove the claims that call them settled. Remove the span advice for a Tooltip on a disabled item.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. RFC Request For Comments. scope: menu Changes related to the menu. type: new feature Expand the scope of the product to solve a new problem. v9.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants