Skip to content

fix(core): TopNavMegaMenu anchors to its trigger outside a <nav> (#4905) - #4916

Merged
imdreamrunner merged 4 commits into
meta:mainfrom
is-jain:fix/topnavmegamenu-anchor-fallback
Aug 14, 2026
Merged

imdreamrunner merged 4 commits into
meta:mainfrom
is-jain:fix/topnavmegamenu-anchor-fallback

Conversation

@is-jain

@is-jain is-jain commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #4905.

Problem

Opening TopNavMegaMenu in the docsite Properties preview renders the dropdown at the viewport top-left corner, detached from its trigger.

Root cause

DefaultMegaMenu sets its CSS anchor with triggerButtonRef.current?.closest('nav') and only calls popover.triggerRef(...) when a <nav> ancestor is found. The Properties preview renders the component standalone, so no element ever carries the layer's anchor-name. The panel still gets position-anchor/position-area from useLayer, and with no matching anchor position-area computes to none — which pins the top-layer popover to the viewport corner because useLayer's base styles zero the UA popover margins (the exact failure mode already documented in useLayer.tsx's getPositionArea comment).

Fix

Fall back to anchoring on the trigger button itself when there is no <nav> ancestor:

const trigger = triggerButtonRef.current;
popover.triggerRef(trigger?.closest('nav') ?? trigger ?? null);

Inside a TopNav nothing changes — the panel still anchors to the surrounding <nav> and spans below the bar. Standalone, the panel now opens below its trigger and stays associated with the preview area, which is the behavior the issue expects.

Tests

Added an "anchor wiring" describe block to TopNavMegaMenu.test.tsx:

  • inside a <nav>: the <nav> carries the layer anchor name, the trigger does not (existing behavior preserved);
  • without a <nav> ancestor: the trigger itself carries the anchor name, and the popup's position-anchor matches it.

vitest run packages/core/src/TopNav/TopNavMegaMenu.test.tsx — 39 tests pass. All pre-commit check:* scripts pass; changeset included (patch, @astryxdesign/core).

…a#4905)

DefaultMegaMenu set its CSS anchor via triggerButtonRef.current?.closest('nav')
and skipped the triggerRef call entirely when no <nav> ancestor exists — so a
standalone render (like the docsite Properties preview) left no element
carrying the anchor name. The panel's position-area then computes to 'none'
and the top-layer popover pins to the viewport top-left corner.

Fall back to anchoring on the trigger button itself so the panel opens below
its trigger wherever the component is rendered.
@vercel

vercel Bot commented Aug 11, 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 14, 2026 4:17am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 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 (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2118 -
Complexity N/A Very High (163) -

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.


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

github-actions Bot added a commit that referenced this pull request Aug 11, 2026
…or logic

Per review: the Properties preview should render TopNavMegaMenu in its real
context. Declare playground.wrapper: TopNav in TopNavMegaMenu.doc.mjs (the
preview injects the component as children, an alias for startContent) so the
panel anchors to the wrapper's <nav> and opens below the bar. Revert the
trigger-anchor fallback in TopNavMegaMenu.tsx and its tests; drop the
changeset since the published component behavior no longer changes.
@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 14, 2026
…eta#4915)

The docsite generator keeps its own copy of the authoring doc types.
ComponentThemingTarget.deprecatedFor and ComponentThemingDerivedVar.replaces
were added upstream but never mirrored here, so componentRegistry.ts emits
fields its own interfaces reject and the docsite build fails type checking.
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
@imdreamrunner
imdreamrunner merged commit 3112e99 into meta:main Aug 14, 2026
19 checks passed
@github-actions
github-actions Bot deleted the fix/topnavmegamenu-anchor-fallback branch August 14, 2026 07:27

This branch was successfully deployed

1 active deployment
Preview — 7a31e194 Deployed Aug 14, 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. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TopNavMegaMenu dropdown renders at viewport top-left in Properties preview

3 participants