Skip to content

fix(TopNav): clamp mega menu panel to viewport width - #4558

Merged
imdreamrunner merged 3 commits into
mainfrom
fix/topnav-mega-menu-overflow
Jul 30, 2026
Merged

fix(TopNav): clamp mega menu panel to viewport width#4558
imdreamrunner merged 3 commits into
mainfrom
fix/topnav-mega-menu-overflow

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Problem

The desktop TopNavMegaMenu panel is an anchored top-layer popover with no size constraints:

  • Vertical — a tall menu (many items + featured card) extends past the bottom of the viewport. The clipped content is unreachable because the popover doesn't scroll (see repro screenshot on the tracker). This is the main issue.
  • Horizontal — the content capped at a fixed maxWidth: 960 with no viewport constraint, so on narrow viewports it also ran off the screen edge.

Tracked in the responsive-web effort (#4476).

Fix (stopgap)

The proper long-term answer for narrow viewports is a bottom-sheet presentation, but that's still WIP in lab. Until then, keep the menu on screen while still anchoring below the nav:

  • Height: clamp the anchored layer to the space available below the nav. The layer is positioned with position-area: self-block-end, so its containing block spans from the nav's block-end to the viewport edge — max-height: calc(100% - gutter) is exactly that space, and it accounts for the nav offset automatically. The layer becomes a flex column so the panel shrinks and its content scrolls internally (overflowY: auto + overscroll-behavior: contain), keeping the surface radius/shadow static at the edges.
  • Width: maxWidth: min(960px, calc(100dvw - gutter)) so the panel never exceeds the viewport width. Desktop (≥960px) behavior is unchanged.

Uses only StyleX-supported values (min()/calc()/100dvw) — Dialog already uses 100dvw, and DropdownMenu/ContextMenu already cap anchored panels with maxHeight + internal scroll.

Testing

  • pnpm --filter @astryxdesign/core test TopNavMegaMenu — 21 passing
  • pnpm --filter @astryxdesign/core build — StyleX compiles the clamps
  • pnpm --filter @astryxdesign/core lint — 0 errors

Draft: still want to confirm the scroll + reflow visually across breakpoints in Storybook before marking ready.

The desktop mega-menu panel capped its content at a fixed 960px with no
viewport constraint, so on narrow viewports the anchored popover extended
past the screen edge and content was clipped. Clamp the panel width to
min(960px, 100dvw - gutter) so it always fits the viewport.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 30, 2026
@vercel

vercel Bot commented Jul 30, 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 Jul 30, 2026 7:51pm

Request Review

@github-actions

github-actions Bot commented Jul 30, 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

TopNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2105 -
Complexity N/A Very High (157) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


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

Use a 16px gutter (--spacing-4) instead of 24px so the panel gets more
usable width on narrow viewports.
github-actions Bot added a commit that referenced this pull request Jul 30, 2026
github-actions Bot added a commit that referenced this pull request Jul 30, 2026
@cixzhang
cixzhang marked this pull request as ready for review July 30, 2026 19:37
A tall mega menu ran off the bottom of the viewport with no way to reach
the clipped content (e.g. the featured card). Clamp the anchored panel to
the space available below the nav and scroll its content internally, while
still anchoring below the nav. This is a stopgap until a mobile bottom-sheet
presentation lands.
github-actions Bot added a commit that referenced this pull request Jul 30, 2026
@imdreamrunner
imdreamrunner merged commit 90ae6c6 into main Jul 30, 2026
18 checks passed
@github-actions
github-actions Bot deleted the fix/topnav-mega-menu-overflow branch July 31, 2026 07:03
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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants