Skip to content

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

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

LukasTy wants to merge 394 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.

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

  • Theme types: c6c5ed3e7b includes the MuiMenu2* entries in the standard theme types. Most component types import these theme types. So a TypeScript program that imports Material UI loads about 150 more declaration files from Menu2, Base UI, and Floating UI. This also occurs when the app does not use Menu2. With a lib older than ES2020, the program also loads the es2020.intl lib. The opt-in Unstable_Menu2/themeAugmentation import that this commit removes avoided this cost, but apps that set MuiMenu2* theme keys needed one more import. Should we keep the default registration, or restore the opt-in import? Both choices keep @base-ui/react as a direct dependency of @mui/material.
  • Classic theme keys: Menu2 parts render classic components: Divider, ListSubheader, ListItemIcon, List, Paper, and ButtonBase. So the theme defaults and styles of these classic keys also reach Menu2, for example MuiDivider.defaultProps.variant. Menu2 now resolves the MuiDivider variant and the MuiListSubheader inset, so an inset from these defaults lines up with the Menu2 items. Should the Menu2 parts stay open to these classic keys, or separate from them, as Menu2 already does for MuiMenu and MuiMenuItem? See open question 2.

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. Nobody reported the bug upstream yet.
  • Base UI on React 17: a Menu2Trigger with openOnHover and no id does not open on hover (RFC known issue). Nobody reported this upstream yet. 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. TablePagination also renders the classic MenuItem, and Select options usually use it. A theme that styles all menus needs the MuiMenu, MuiMenuItem, and MuiMenu2* keys. Their move to Menu2 is a separate decision.

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 ±8.7% (±12.0% at worst) · ran 3m 39s · 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 15 commits November 24, 2026 15:25
The popup slot bases and `Menu2ItemBase` already apply their theme styles before `sx`. The unnamed wrappers around them in `Menu2Popup` and `Menu2Item` added nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The variant only checks a flag. Items set `divider` in the owner state, which object rules also match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The popup slot props accepted any key, so callbacks also matched the object type. Allow only the known props and data attributes. The backdrop slot gets `sx` explicitly, and the submenu list uses the shared slot type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Menu2 slot props now reject data-* keys until the user augments DataAttributesOverrides, as on every other component.

The Menu2 tests now find elements with role and text queries. Elements without a role, such as the positioner, portal, list, and indicators, are found from a role-found element or by their utility classes. Test ids stay only on elements without a role.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LukasTy and others added 8 commits November 25, 2026 15:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>

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