Repository navigation
Conversation
Deploy previewBundle size
PerformanceNo 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. |
b8d5972 to
905a982
Compare
|
Nice work @LukasTy. Some comments/questions: Open questions1. 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 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, 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:
Other
|
|
Thanks for the thorough pass, @aarongarciah. 🙏 Open questions
Other
|
siriwatknp
left a comment
There was a problem hiding this comment.
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.
siriwatknp
left a comment
There was a problem hiding this comment.
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.
Great idea! 👍 |
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>
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>
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>
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.mdanddocs/data/material/migration/upgrade-to-menu-v2/upgrade-to-menu-v2.mdin this PR.Changes since the last review
2d07df256areplaces the single-component API. Review comments before this commit can name props and classes that no longer exist.Menu2Triggerreplaces thetriggerprop andslotProps.trigger. It requiresrenderwith an element or a typed callback. Both trigger components now takeopenOnHover,delay, andcloseDelaydirectly, as in Base UI. ThenativeButtonprop also belongs on the trigger.render. It changes the element or composes a component while keeping Material styles, theme overrides, and item ripple.slots.rootandslotProps.root. A replacement root takes precedence overrenderand can omit Material styles. It still receives Base UI behavior props, refs, utility classes, and children. Forward these to preserve behavior and accessibility. AslotProps.rootcallback 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, withrender, ripple.Menu2andMenu2Submenurender no element and accept only open-state and behavior props.Menu2PopupandMenu2SubmenuPopuptake the positioning, portal, transition,elevation,finalFocus, and slot props.rootslot is now the menu surface, which was thepaperslot. The stacking layer, which was therootslot, is nowportal.MuiMenu2andMuiMenu2Submenusupport onlydefaultProps. Popup styles move toMuiMenu2PopupandMuiMenu2SubmenuPopup.MuiMenu2Triggeris a new key that supports onlydefaultProps.c6c5ed3e7bregisters theMuiMenu2*theme types by default and removes theUnstable_Menu2/themeAugmentationentry point.4fb0a872d0removes detached triggers.0a25dc1f9amoves modality to Material UI. Menu2 passesmodal={false}to Base UI and locks page scroll throughModalManager. Touch opens also lock, and a second trigger click closes the menu with reasonoutside-press.282c6b7ca7fixes the Dialog issues from the interop review:backdropslot is now a visual layer only: it renders only when configured and lets clicks through.slots.backdrop={null}removes only the visual layer. Usemodal={false}to let outside clicks through.disableRestoreFocusworkaround only forcloseOnClick={false}, a menu withoutMenu2Trigger, and a customfinalFocus.finalFocusref 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.positionMethod="fixed"on every popup level for acontainerinside a Dialog. Plain Base UI needs the same setting.9cf9c434e9replacesslots.indicatorIconandslotProps.indicatorIconwithiconandcheckedIconprops onMenu2CheckboxItemandMenu2RadioItem, as in Checkbox and Radio. ThemedefaultPropscan set them. The icon keeps theindicatorIconclass andstyleOverrides.indicatorIcon, and defaults to the small size.cc7d36c9c5addsstartAdornment,endAdornment, andinsetto all item parts. They replaceListItemIcon,ListItemText, and a shortcutTypographyin the children:<MenuItem startAdornment={<ContentCut fontSize="small" />} endAdornment="Ctrl+X">Cut</MenuItem>.insetkeeps 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 getsstartAdornment,endAdornment, andinsetclasses and theme keys;MuiMenu2Itemkeys apply to all parts.409a99b4acremovesdense. Menu2 has no dense mode. The popup List setsdense={false}, soslotProps.list, the MuiList theme default, and an outer dense List do not change Menu2.76534146a3removes the code that Menu2 shared with the classic Menu.Menu2ItemBasehas its own copy of the item styles. The classicMenuandMenuItemare the same as on master. The rendered styles do not change.9499cea4b1aligns inset separators and group labels with the item labels. An insetMenu2Separatoruses 52px in every position. An insetMenu2GroupLabeluses 52px, or 36px withdisableGutters.0317ba4900removes the classic child composition styles. Items no longer restyleListItemIcon,ListItemText, or a plainDivider, and they no longer provide aListContext. These children render with their List styles. UsestartAdornment,endAdornment,inset, andMenu2Separator.7a793d8033andee12bae260make the slot prop types strict. Unknown keys in the object form are type errors.data-*keys need theDataAttributesOverridesaugmentation, as on the other components.236247c044passes the Base UI state as is to the itemrenderfunctions, as the groups, labels, and separators already do.divider,disableGutters, andinsetstay inownerState. Each part exports aMenu2*Statealias for its render state.fcb588ec25addsrendertoMenu2PopupandMenu2SubmenuPopupfor the menu surface. It keeps the Paper, theme, andsxstyles, andslots.roottakes precedence.slotProps.rootno longer acceptscomponent.12a3e08ce8replacescomponentwithrenderonslotProps.listand onslotProps.indicatorof the checkbox, radio, and submenu trigger items.renderkeeps the slot styles, andslots.<slot>takes precedence. A render function gets the Base UI state of its part.7a75b571e8addsrendertoslotProps.portal,slotProps.positioner, andslotProps.backdropwith the same rule. No part or slot takescomponent.e62520a035types theslotPropsand theme callbacks as their runtime value. They receive the props and the live Base UI state, such ashighlighted. Popup callbacks receive only the props.MuiMenu2Itemalso styles the link, checkbox, radio, and submenu trigger items, so itsdisabledandopenfields are optional.31bea1fab3reads thearia-labelof arenderelement onMenu2PopupandMenu2SubmenuPopup, and theidof aslotProps.portal.renderelement, as Base UI does. Before, the trigger stayed the menu name, andaria-ownspointed to a missing ID.Menu2GroupLabelalso registers theidof itsrenderelement, so the group keeps its name.49aefe75dbalso reads the elementaria-labelwhen thearia-labelprop isundefined.fa98657248keeps the focus thatonOpenChangemoves 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.e571095599resolves theMuiDividervariant and theMuiListSubheaderinset inMenu2SeparatorandMenu2GroupLabel. An inset from these theme defaults now lines up with the Menu2 items, and the owner state shows the resolved values.4a2609702estates that a Menu v2 menu takes only Menu v2 parts. A classicMenuItemthrows insideMenuPopup, also throughrender. Other classic components render, but Base UI does not register them as items, so arrow keys and typeahead skip them. Other components compose throughrenderon a part. The upgrade guide, the Menu v2 page, and the RFC state the rule, and the customized demo usesstartAdornment.4a3b07912dstates that on React 17, aMenu2TriggerwithopenOnHoverneeds a uniqueidfrom the first render. Anidthat an effect sets later, such as one fromunstable_useId, does not work. The Menu v2 page also says that a classicMenuItemthrows throughrender. The RFC bundle table adds a classic Menu +unstable_enhanceDensitycase (+234 B gzip) and uses the merge base9769f52fee.Scope
@mui/material/Unstable_Menu2*entry points for 14 components. The classic Menu API does not change.Menu2controls behavior and renders no element.Menu2Triggermerges behavior into the element supplied throughrender.Menu2Popupowns the menu surface, positioning, portal, and transition. Submenus use the same three parts.Menu2Submenurenders no element, andMenu2SubmenuPopupowns the submenu surface. UnlikeMenu2Trigger,Menu2SubmenuTriggerrenders its own menu item, and its children are the item content.dense, and the popup list ignores it.Menu,MenuList, orMenuItem.MuiMenu2PopupandMuiMenu2SubmenuPopup; Menu2 item theme keys remain unchanged. Popup refs,sx, and HTML props target the menu surface. The renderlessMenu2andMenu2Submenusupport behavioraldefaultProps, but no slots or DOM styling. Style the element supplied toMenu2Triggerdirectly.theme.motion.reducedMotion. Other compatible Material transitions and CSS animations remain available.MuiMenu2*entries; no augmentation import is needed.@mui/materialadds@base-ui/react^1.9.0as 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.
ModalManageradds an internallockScroll(container)method, anduseModalexports 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,ModalManagerruns the master code. The public@mui/material/Modalexports do not change.RadioButtonIconmerges aclassNameprop into its root, soMenu2RadioItemcan add theindicatorIconclass.Radiodoes not passclassName, so its output does not change.enhanceHighContrastadds forced-colors overrides for theMuiMenu2*items, including the end adornment.unstable_enhanceDensityadds 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.mtsinlines@base-ui/reactand@base-ui/utilsin the jsdom tests on React 17. Their ESM files importreact/jsx-runtimewithout an extension, and Node cannot resolve that import for React 17.@mui/material/stylesexportsComponentsOwnerStateList. Theme variants and style overrides readownerStatefrom it. It extendsComponentsPropsList. The Menu2 item, radio group, and separator keys also include the resolved owner state, such ashighlighted.@mui/materialimports from the PigmentContainer, PigmentGrid, and PigmentStack API pages. PigmentContainer also lists itsMuiContainerclasses.typescript-to-proptypespreservesnullin React element-type unions.Menu2Itemrow, so its regression screenshot changes.focus()in the browser test setup now reads the focus options before it calls the native method without arguments. Base UI checkspreventScrollsupport through these options, and without the read it does not return focus after an outside press.Before release
menus.a11y.json. In the non-modal fixture, axe reports anaria-hidden-focusfailure 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-valuepasses in all three fixtures. The fixtures skip assertions only foraria-hidden-focus.containeronMenu2Popup. The others are Material UI integration gaps and API limits, for example:ModalManagercan hide a retained popup inside a kept-mounted Dialog. With the default portal container, leavekeepMounteddisabled onMenu2Popupinside a kept-mounted Dialog. Menu2 also has the known limits of the Modal scroll lock, the same as Dialog: no lock whenhtmlscrolls 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 withdisableScrollLockalso 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. Acontainerinside a positioned element that clips its overflow, such as the Dialog paper, clips the menu. SetpositionMethod="fixed"onMenu2Popupand on eachMenu2SubmenuPopup.v9.xafter 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.nightlyCircleCI 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.Open questions for the team
c6c5ed3e7bincludes theMuiMenu2*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 alibolder than ES2020, the program also loads thees2020.intllib. The opt-inUnstable_Menu2/themeAugmentationimport that this commit removes avoided this cost, but apps that setMuiMenu2*theme keys needed one more import. Should we keep the default registration, or restore the opt-in import? Both choices keep@base-ui/reactas a direct dependency of@mui/material.Divider,ListSubheader,ListItemIcon,List,Paper, andButtonBase. So the theme defaults and styles of these classic keys also reach Menu2, for exampleMuiDivider.defaultProps.variant. Menu2 now resolves theMuiDividervariant and theMuiListSubheaderinset, 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 forMuiMenuandMuiMenuItem? See open question 2.Known limitations and follow-ups
The RFC known issues list the user-facing limits. These items are for reviewers:
data-rootowneridattribute, setsdata-base-ui-inert, and has three focus workarounds that depend on Base UI 1.9.0 timing. At03543cfbd2, 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.Menu.GroupLabelregisters its generated ID, not the ID of arenderelement, so plain Base UI leaves the group unnamed.Menu2GroupLabelworks around it for the element form. Nobody reported the bug upstream yet.Menu2TriggerwithopenOnHoverand noiddoes not open on hover (RFC known issue). Nobody reported this upstream yet. The docs tell users to set anidfrom the first render, and the tests set a static triggerid.slotProps.portal.renderfunction that sets its ownidleavesaria-ownson a missing ID. Plain Base UI reads the ID from the returned element. UseslotProps.portal.idor a render element.highlightedfor the five item parts androotforMenu2Triggeras 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.slotPropscallback returns, so unknown keys andcomponentpass. This is a TypeScript limit, also withoutWithDataAttributes, so classic components have the same gap. Menu2 also has noMenu2*SlotPropsOverridesinterfaces.Menu2Submenudoes not warn in development when it has noMenu2SubmenuTrigger. A plainMenu2Itemin its place does not open the submenu. Base UI does not warn either.List, andslotProps.listtakesListPropswithoutdense. A follow-up can replaceList, and that change also changes theslotProps.listAPI.Menu. TablePagination also renders the classicMenuItem, and Select options usually use it. A theme that styles all menus needs theMuiMenu,MuiMenuItem, andMuiMenu2*keys. Their move to Menu2 is a separate decision.Experiments