Skip to content

[menu] Implement content transitions with Viewport - #4060

Merged
michaldudak merged 15 commits into
mui:masterfrom
michaldudak:menu-viewport
Mar 12, 2026
Merged

michaldudak merged 15 commits into
mui:masterfrom
michaldudak:menu-viewport

Conversation

@michaldudak

@michaldudak michaldudak commented Feb 12, 2026 •

Copy link
Copy Markdown
Member

@michaldudak michaldudak added component: menu Changes related to the menu component. type: new feature Expand the scope of the product to solve a new problem. labels Feb 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 12, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4060
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4060
    

commit: 8e67c00

@mui-bot

mui-bot commented Feb 12, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+1.09KB(+0.23%) 🔺+441B(+0.29%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c2eb2d7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69b16c6b8192ce0008a8c902
😎 Deploy Preview https://deploy-preview-4060--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Adds Menu.Viewport component to enable animated content transitions when using detached triggers. The viewport wraps menu content and handles morphing between different content states as users switch between triggers.

Key changes:

  • New MenuViewport component with transition state management
  • Enhanced usePopupViewport hook with ReactDOM.flushSync for better animation timing
  • MenuPositioner now tracks trigger changes and applies adaptiveOrigin middleware when viewport is present
  • Comprehensive test coverage for viewport transitions and morphing behaviors
  • Documentation and demos showing position, size, and content animations

Minor issue:

  • Documentation comment in MenuViewportDataAttributes.ts:24 missing 'trigger-change' type value

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows repository guidelines (uses useIsoLayoutEffect, useStableCallback, proper hook patterns), includes comprehensive tests, and the only issue found is a minor documentation comment inconsistency that doesn't affect runtime behavior
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/menu/viewport/MenuViewport.tsx New MenuViewport component implementation - clean, follows repository guidelines
packages/react/src/menu/viewport/MenuViewportDataAttributes.ts Data attributes enum with documentation comment missing trigger-change type
packages/react/src/utils/usePopupViewport.tsx Improved viewport hook using ReactDOM.flushSync and proper null checks
packages/react/src/menu/positioner/MenuPositioner.tsx Added viewport support with adaptiveOrigin and trigger change tracking
docs/reference/generated/menu-viewport.json API reference documentation missing trigger-change in data-instant type

Last reviewed commit: 57140e8

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

19 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements the Menu.Viewport component to enable animated content transitions when using detached triggers with the Menu component. This mirrors the existing Viewport implementations in Popover, PreviewCard, and Tooltip components, providing a consistent API across the library.

Changes:

  • Added Menu.Viewport component for content transition animations with detached triggers
  • Enhanced usePopupViewport hook with ReactDOM.flushSync for more reliable animation timing
  • Added trigger-change instant type to Menu store for transition behavior control
  • Integrated adaptiveOrigin middleware conditionally based on viewport presence

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/react/src/utils/usePopupViewport.tsx Improved animation timing with ReactDOM.flushSync and defensive null handling for CSS variables
packages/react/src/menu/viewport/MenuViewport.tsx New viewport component implementation following established patterns
packages/react/src/menu/viewport/MenuViewportDataAttributes.ts Data attribute enum definitions for viewport states
packages/react/src/menu/viewport/MenuViewportCssVars.ts CSS variable enum definitions for popup dimensions
packages/react/src/menu/viewport/MenuViewport.test.tsx Comprehensive test suite covering transitions and direction calculations
packages/react/src/menu/store/MenuStore.ts Added hasViewport state and trigger-change instant type
packages/react/src/menu/root/MenuRoot.detached-triggers.test.tsx Added regression test for inline scale styles
packages/react/src/menu/positioner/MenuPositioner.tsx Integrated adaptiveOrigin middleware and trigger change detection
packages/react/src/menu/popup/MenuPopup.tsx Added popup element tracking callback and updated instant type
packages/react/src/menu/index.ts Added Viewport type exports
packages/react/src/menu/index.parts.ts Added Viewport component export
docs/src/app/(private)/experiments/menu/triggers.tsx Added Viewport to experimental demo
docs/src/app/(docs)/react/components/page.mdx Updated component structure documentation
docs/src/app/(docs)/react/components/menu/page.mdx Added comprehensive documentation for animating menus
docs/src/app/(docs)/react/components/menu/demos/detached-triggers-full/* New demo implementations in Tailwind and CSS modules
docs/reference/generated/menu-viewport.json Generated API reference documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57140e8998

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 2, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 9, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 10, 2026
@atomiks

atomiks commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review

Overview

This PR adds Menu.Viewport so one detached-trigger menu can animate its content, size, and position while reusing the same popup. It also hooks Menu into the shared popup viewport machinery and adds the positioner/state plumbing needed for those transitions.

Findings (None)

No blocking issues found in this patch.

Confidence: 4/5

High confidence based on a full pass over the current branch diff, a focused sweep of the new viewport/control-flow paths, targeted JSDOM and Chromium verification of the changed Menu tests, and a small Chromium DOM benchmark for the new transition work. Residual risk is limited to highly app-specific styling or accessibility edge cases around cloned transition content.

Notes

  • I am not re-raising the earlier duplicate-ID concern as a blocker. The current branch forces the live subtree to remount when the active trigger changes, and again if the payload arrives a render later, via usePopupContentKey in packages/react/src/utils/usePopupViewport.tsx:88-90 and packages/react/src/utils/usePopupViewport.tsx:339-367. That means the active subtree gets fresh generated IDs instead of reusing the exiting subtree's IDs. I also tried a focused Chromium repro with grouped menu labels and did not reproduce duplicate current/previous ID collisions during the transition window.
  • The size tradeoff is still real but bounded. The bundle checker on this PR reports +1.09KB parsed / +441B gzip versus master, which mostly looks like the cost of exposing Menu.Viewport and wiring Menu into the shared viewport path (packages/react/src/menu/viewport/MenuViewport.tsx, packages/react/src/menu/positioner/MenuPositioner.tsx, packages/react/src/menu/store/MenuStore.ts, and packages/react/src/utils/usePopupViewport.tsx).
  • Focused Chromium DOM micro-check for representative detached-trigger switches (10 samples, 300 switches per sample):
Ref Mean (ms) p50 (ms) p95 (ms) Sample size
master baseline 3.18 3.10 3.80 10
PR head 4.67 4.50 4.90 10
PR head + cloned-subtree sanitization alternative 6.67 6.40 7.00 10

On this synthetic switch path, the current implementation adds about 1.49ms / 300 switches relative to master (roughly 5µs per switch), while the reverted cloned-subtree sanitization approach would add roughly another 2.00ms / 300 switches on top of the current path. That lines up with the code tradeoff here: the viewport feature is not free, but the remaining transient clone window is short-lived and the heavier sanitization fix appears more expensive in both bytes and per-switch DOM work.

  • Verified with pnpm test:jsdom MenuViewport --no-watch, pnpm test:chromium MenuViewport --no-watch, and pnpm test:chromium MenuRoot.detached-triggers --no-watch; all passed.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 11, 2026
@michaldudak

michaldudak commented Mar 11, 2026 •

Copy link
Copy Markdown
Member Author

This might be slightly problematic if the contents are styled based on their IDs, so there is a tradeoff.
Traversing all the cloned nodes and modifying their attributes would impact performance, so I'm ignoring it for now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@michaldudak
michaldudak merged commit 6cebc00 into mui:master Mar 12, 2026
6 checks passed
@michaldudak
michaldudak deleted the menu-viewport branch March 12, 2026 11:14
atomiks pushed a commit to michaldudak/base-ui that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: menu Changes related to the menu component. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants