Skip to content

Improve DropdownMenu responsive fit and presentation guidance - #5395

Merged
rubyycheung merged 30 commits into
mainfrom
fix/dropdown-menu-responsive-interaction
Aug 30, 2026
Merged

rubyycheung merged 30 commits into
mainfrom
fix/dropdown-menu-responsive-interaction

Conversation

@rubyycheung

@rubyycheung rubyycheung commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

DropdownMenu uses usePopover directly, so Popover's viewport-fitting work does not automatically apply here. The current menu can reach or exceed the browser edge when a consumer requests a wide menuWidth, and submenu flyouts own the same separate geometry. The fixed 300px menu height is also not aware of a shorter visual viewport.

The presentation guidance also needs to distinguish two contracts without turning either into a universal rule:

  • DropdownMenu is an anchored menu for concise contextual actions.
  • A product may explicitly render the same short, flat actions in an action-sheet-style BottomSheet when that bottom-edge modal touch contract fits its experience.

Core DropdownMenu does not automatically change presentation.

Changes and rationale

Change Problem it solves Why this approach
Cap root menus and submenu flyouts to available viewport width with token and safe-area gutters. Wide requested widths and intrinsic content could reach or exceed a compact viewport edge. Root menus use alignment-specific collision space, so ordinary start/end-aligned menus stay flush with the trigger while oversized menus preserve the opposite viewport gutter. Submenu flyouts keep flip-first positioning and a verified 4px parent-to-child gap; their width caps apply only after the browser chooses a side.
Cap menu height to the smaller of 300px and the available dynamic viewport height. A fixed 300px menu can be taller than the visible area on a short viewport. This preserves the existing 300px product limit while respecting the space that actually exists. 100vh/100vw fallbacks preserve older-browser behavior.
Add scrolling only after measured block-axis overflow exists, and make that scroll region keyboard-focusable. Always applying overflow: auto turns fitting menus into scroll containers and can clip content unnecessarily; a scroll region with only programmatically focusable menu items fails keyboard access checks. Resize, mutation, image-load, window, and visual-viewport changes remeasure an open menu. Fitting menus keep normal overflow and tabIndex={-1}; oversized menus scroll internally with overscroll containment and use tabIndex={0} while open. Tab still follows the existing menu dismissal behavior.
Preserve menuWidth as a minimum width, capped by available space. The implementation already treated menuWidth as min-width, despite docs calling it a fixed/custom width. Changing it to exact width would be an undocumented compatibility break. Consumers keep the existing growth behavior. The dynamic minimum uses the broadly supported viewport fallback, while the layer's modern cap still applies safe-area-aware logical sizing.
Apply the same fit rules to DropdownMenuSubMenu. Submenu flyouts own separate layer geometry and would not inherit root-menu constraints. Root menus and every flyout level now follow the same viewport contract.
Add real-viewport stories for wide root menus, tall overflow, submenu edge fit, and compact drill-in hierarchy. Unit styles do not prove rendered placement and wrapper geometry. The stories use the actual Storybook iframe viewport, retain normal trigger toggling/dismissal, and auto-open only through play. Root menus preserve the trigger edge; concise submenus flip with a measured 4px gap; hierarchy that cannot fit uses a separate explicit drill-in BottomSheet example.
Add explicit action-sheet and product-owned adaptive examples. Consumers need to see how the same short, flat actions can use different interaction contracts. The forced story makes BottomSheet directly reviewable. The adaptive example combines compact width, coarse pointer, and no hover, but is labeled as one product policy, not a Core default or universal breakpoint.
Add an explicit compact drill-in hierarchy story. A viewport-contained submenu may overlap its parent when two flyouts cannot fit side by side, which is technically contained but not a useful compact-touch hierarchy. The BottomSheet example drills from project actions into project destinations with a Back action. It is product-owned and opt-in; Core DropdownMenu does not transform automatically.
Correct component guidance. Content length, search, multiselect, richness, or hierarchy alone does not prove that Dialog or BottomSheet is correct. The docs now recommend reevaluating the actual task and interaction contract instead of prescribing a component from one content trait.
Add regression coverage and a patch changeset. Width, overflow, and submenu behavior can regress independently. Tests cover default/custom widths, viewport-aware height, both overflow outcomes, and flyout containment.

Research boundaries

Research informed these conclusions:

  • WCAG 2.2 AA requires reflow at 320 CSS px and a 24×24 CSS px target minimum (or an allowed exception); it does not require Google's 48×48 convention.
  • Menu activation must not depend on hover. Click/tap and the established APG keyboard model remain available.
  • Floating menus should flip/shift/constrain to available space and make genuinely overflowing content reachable.
  • A short, flat action set can be presented as an action sheet on a compact touch surface.
  • These findings do not establish that scrolling, search, multiselect, rich content, or hierarchy automatically requires Dialog or BottomSheet. That choice depends on the actual task and interaction contract.

Primary references: WCAG Reflow, WCAG Target Size (Minimum), WAI-ARIA Menu Button Pattern, Material 3 Menus, Material 3 Bottom Sheets, Apple HIG Menus, and React Aria Menu.

Responsive and Interaction Readiness

Scenario Result Evidence
Wide viewport + fine pointer + hover Pass Existing anchored menu and hover behavior remain; no presentation switch occurs.
Narrow viewport + fine pointer + hover Pass Root and submenu widths cap to real viewport gutters; fitting content does not become a scroll container.
Narrow viewport + coarse pointer + no hover Pass Trigger activation remains tap/click based. The action-sheet recipe is explicit and product-owned.
Wide viewport + coarse pointer + no hover Pass Touch capability alone does not replace the anchored menu.
Block-axis overflow Pass Tall content caps to available space, scrolls internally, and exposes a keyboard-focusable scroll region; fitting content keeps overflow: visible.
Target size Pass Measured menu rows are about 32px high, above WCAG 2.2 AA's 24px floor.
Keyboard behavior Pass Existing arrow navigation, Enter/Space, typeahead, Escape, Tab dismissal, submenu keys, and focus restoration remain covered.
Adaptive presentation Pass Core never silently transforms; stories show explicit BottomSheet and one clearly labeled example policy.
iOS-specific behavior Not claimed Desktop Chromium evidence does not establish iOS Safari, VoiceOver, or physical-device touch dispatch.

Compatibility and scope

  • No public prop is added or removed.
  • menuWidth retains its existing minimum-width behavior.
  • MoreMenu inherits the root DropdownMenu fit behavior because it composes DropdownMenu.
  • DropdownMenuSubMenu is updated directly.
  • ContextMenu owns separate popup geometry and is not changed here.
  • Core DropdownMenu does not automatically become BottomSheet.

Validation

  • pnpm exec vitest run packages/core/src/DropdownMenu/DropdownMenu.test.tsx packages/core/src/DropdownMenu/DropdownMenuSubMenu.test.tsx packages/core/src/DropdownMenu/DropdownMenuSelectable.test.tsx — 111 tests pass
  • pnpm -F @astryxdesign/core build
  • pnpm -F @astryxdesign/storybook typecheck
  • targeted ESLint and Prettier
  • pnpm check:repo
  • Headless Chromium at 320×568:
    • requested 640px root menu: 16px–304px, 288px wide, no page overflow
    • concise 140px submenu: parent 218–358px, child flips to 74–214px, preserving a measured 4px gap
    • fitting menus: overflow-y: visible
    • tall menu: 300px client height / 546px scroll height, overflow-y: auto
  • Presentation check at 390×844:
    • fine-pointer/hover environment: anchored DropdownMenu
    • compact touch environment: action-sheet BottomSheet in the opt-in example

@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 30, 2026 8:34pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
@github-actions github-actions Bot added the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

BottomSheet (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3195 -
Complexity N/A Very High (258) -
ContextMenu (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 543 -
Complexity N/A Very High (67) -
DropdownMenu (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2099 -
Complexity N/A Very High (234) -
MoreMenu (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 87 -
Complexity N/A Low (4) -
MultiSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1603 -
Complexity N/A Very High (211) -
Selector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1934 -
Complexity N/A Very High (197) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

Status: Skipped — Broad stable scope is deferred to the daily release gate. It covers 3136 trusted baseline shots instead of recapturing them for this PR. View the report


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@xinzi-bot

Copy link
Copy Markdown

I ran the three new readiness stories against the PR base (20bae6c) and current head (507b85a), using the PR's story definitions on both sides.

Before/after screenshot comparison (Pixelcloud)

Concrete results:

  • Viewport width, 320×568: base renders the requested 640px menu at x=0…640; this PR constrains it to x=16…288 (272px), fully inside the viewport.
  • Short viewport, 320×240: base keeps the 300px menu at y=4…304, clipping 64px below the viewport. This PR caps it to 208px at y=28…236; the full 546px content remains internally scrollable, and the overflowing menu becomes a keyboard tab stop.
  • Submenu, 320×568: this surfaced something that does not match the PR's stated 4px-gap result. Base flips the 140px submenu left to x=8…148, beside the parent at x=148…288. This PR instead places it at x=172…312, overlapping the parent by 116px. The screenshot's third row shows it directly. That looks worth fixing or explaining before merge.

The Pixelcloud asset is linked rather than embedded so the full-resolution comparison opens separately.

[Reviewed by Agentcloud]

@xinzi-bot xinzi-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.

This PR is a net improvement, and I found no regressions or bugs that should block merging.

Three non-blocking follow-ups:

  • Clarify that menuWidth strings support CSS length/percentage/math values such as 240px, 50vw, calc(...), and clamp(...); intrinsic and automatic keywords are outside the intended contract.
  • Apply the intended viewport gutter consistently to horizontally positioned menus.
  • Make custom-width caps fully safe-area-aware.

Validation passed: 111 focused DropdownMenu tests, full workspace build, strict lint, and Storybook typecheck.

@meta meta deleted a comment from xinzi-bot Aug 27, 2026
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 27, 2026
@rubyycheung

Copy link
Copy Markdown
Contributor Author

Fixed the blocking menuWidth compatibility regression in 679ec07:

  • intrinsic and CSS-wide values such as max-content, fit-content, and auto now remain valid CSS
  • those values use inline-size, allowing the existing max-inline-size viewport constraint to cap them
  • numeric and length-string values retain the existing minimum-width behavior
  • the same resolver is shared by the root menu and submenu flyouts

Validation: 117 focused tests pass; Core typecheck, strict changed-file lint, and the Core production build pass.

@xinzi-bot xinzi-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.

I rechecked exact head 1949245. The adaptive examples look fine, but the prior controlled close issue still reproduces in source: prop-driven isMenuOpen={false} skips setOpen(false), so submenuPath is not cleared and reopening can start in the old submenu. Please reset the path whenever effective open state becomes false.

[Automated review]

@rubyycheung

Copy link
Copy Markdown
Contributor Author

Fixed the controlled-close navigation issue in 3171300. Bottom-sheet navigation now clears whenever the effective open state transitions to false, including prop-driven closes, and a regression test covers drill in → controlled close → reopen at the root. The focused DropdownMenu suite passes (90 tests) and the touched files pass ESLint.

@xinzi-bot xinzi-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.

Exact head 3171300 fixes the controlled close issue; the test covers close-then-reopen at root. @imdreamrunner, this looks ready for your approval.

[Automated review]

@rubyycheung
rubyycheung enabled auto-merge (squash) August 30, 2026 19:14
* Improve DropdownMenu responsive fit and presentation guidance

* fix DropdownMenu scroll region keyboard access

* docs clarify compact submenu presentations

* fix DropdownMenu anchor alignment and submenu examples

* fix DropdownMenu submenu spacing

* docs minimize DropdownMenu guidance diff

* fix(DropdownMenu): preserve intrinsic width values

* feat: add adaptive menu presentations

* chore: version packages for v0.5.1 (#5661)

* refactor(i18n): pre-build lookup map for translations (#4696)

* fix(popover): improve responsive fit and focus

* Preserve Popover compatibility when constraining overflow

* Add real-viewport Popover overflow stories

* Refine Popover overflow story

* Restore Popover story dismissal behavior

* docs clarify Popover presentation guidance

* docs render Popover evidence in real viewports

* fix(Popover): address accessibility review

* fix DropdownMenu controlled close navigation

* fix(Popover): observe overflow only while open

* fix(Popover): align mobile presentation behavior

* docs(Popover): tighten bottom sheet spacing

* fix(menu): align mobile bottom sheets

* fix(Popover): hide container focus outline

* fix(ContextMenu): prevent touch selection

* docs(ContextMenu): add bottom sheet example

* fix(MoreMenu): preserve touch feedback

* docs(MoreMenu): add bottom sheet example

* fix(ContextMenu): reliably suppress touch selection

* fix(ContextMenu): improve mobile doc examples

* fix(MoreMenu): reduce bottom sheet padding

* refactor(menu): share adaptive sheet infrastructure

* fix(menu): preserve focus without touch rings

* fix(BottomSheet): keep browser edge surface-colored

* fix(ContextMenu): drill into sheet submenus

* Add adaptive Selector and MultiSelector presentations (#5685)

* feat: add adaptive selector presentations

* fix: refine selector bottom sheet interactions

* refactor(selector): use shared adaptive policy

* fix(selector): preserve focus without touch rings

* fix selectors bottom sheet focus target

---------

Co-authored-by: Cindy Zhang <[email protected]>
Co-authored-by: Li Hongzhang <[email protected]>
github-actions Bot added a commit that referenced this pull request Aug 30, 2026
@rubyycheung
rubyycheung merged commit 98dd983 into main Aug 30, 2026
23 checks passed
@github-actions
github-actions Bot deleted the fix/dropdown-menu-responsive-interaction branch August 31, 2026 06:28

This branch was successfully deployed

1 active deployment
Preview — d3a10c1c Deployed Aug 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants