Skip to content

fix(TopNavMegaMenu): positioning, keyboard, alignment, and responsive layout - #622

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/mega-menu-positioning
Mar 15, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/mega-menu-positioning

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Major overhaul of both XDSTopNavMegaMenu and XDSTopNavMenu, making them consistent with each other and fully accessible.

Both Menus

Focus Trapping (useXDSPopover)

  • Both now use useXDSPopover for focus trapping — tab cycles within the menu
  • XDSTopNavMenu adds useListFocus for arrow key navigation (linear list)
  • XDSTopNavMegaMenu uses tab navigation (2D grid)

Hover + Click Interaction

  • Hover: opens after delay via popover.show({skipAutoFocus: true}) — no focus steal
  • Click: toggles open/closed, locks against hover dismiss
  • Escape: closes and returns focus to trigger
  • Both have chevron with rotation animation and triggerOpen active state

Slot-Aware Alignment

  • New TopNavSlotContext — TopNav wraps each slot in a context provider
  • Menus read slot context and pass alignment to popover
  • Panel position-area follows the nav item placement automatically

XDSTopNavMegaMenu

Positioning

  • Anchors to parent <nav> for full-width panels
  • Removed position: relative wrapper requirement

Responsive Layout

  • Flex-wrap 2:1 ratio (items flex: 2 1 300px, featured flex: 1 1 200px)
  • Inner items: XDSGrid columns={2} minChildWidth={200}
  • Featured wraps below at narrow widths
  • Transparent layer background — panelContainer provides visual style

Removed

  • isSingleColumn prop (responsive grid replaces it)
  • anchorStretch style
  • Divider div

XDSTopNavMenu

Changes

  • Switched from useXDSHoverCard to useXDSPopover + hover enhancement
  • Focus doesn't open the menu (keyboard: Enter/click to open)
  • Arrow keys navigate items via useListFocus
  • Popover styling: background, shadow, border-radius, padding, 4px offset
  • Transparent layer background

Other

  • useXDSHoverCard: exposed show/hide methods
  • Shell Lab: independent superheading/subheading toggles
  • Shell Lab: all four AppShell variant options
  • Removed isSingleColumn from sandbox mega-menu demo

Test plan

  • Tested both menu styles in Shell Lab across all TopNav alignments
  • Tested click toggle, hover, Escape, Enter, arrow keys, Tab focus trapping
  • Tested responsive layout at various widths

Part of #565

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 15, 2026
@cixzhang
cixzhang force-pushed the navi/fix/mega-menu-positioning branch from 7b61b8d to 44690bb Compare March 15, 2026 06:06
@github-actions

github-actions Bot commented Mar 15, 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

HoverCard · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 217B N/A
Lines of Code N/A 426 -
Complexity N/A Very High (44) -
TopNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 611B N/A
Lines of Code N/A 1048 -
Complexity N/A Very High (59) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 9.4KB 15.2KB 2.4KB

Accessibility Audit

Status: No accessibility violations detected.


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

@cixzhang
cixzhang force-pushed the navi/fix/mega-menu-positioning branch from 44690bb to 715f663 Compare March 15, 2026 21:05
@cixzhang
cixzhang force-pushed the navi/fix/mega-menu-positioning branch from 715f663 to 231a3c1 Compare March 15, 2026 21:23
@cixzhang
cixzhang force-pushed the navi/fix/mega-menu-positioning branch from 231a3c1 to e022230 Compare March 15, 2026 21:25
… focus trapping

Mega menu + menu overhaul addressing #565 findings:

Positioning:
- MegaMenu: anchor to parent <nav> via useXDSPopover
- Menu: anchor to trigger button via useXDSPopover
- Both: slot-aware alignment via TopNavSlotContext
- Removed anchorStretch override and position:relative wrapper requirement

Focus & Keyboard:
- Both use useXDSPopover for focus trapping (tab cycles within menu)
- Menu uses useListFocus for arrow key navigation between items
- MegaMenu uses tab navigation (2D grid, not linear list)
- Click toggles open/closed, locks against hover dismiss
- Escape closes and returns focus to trigger
- Hover as progressive enhancement (show with skipAutoFocus)

Visual:
- Both have chevron with rotation animation
- triggerOpen style for active state (matches XDSTopNavItem selected)
- Menu: popover styling (background, shadow, border-radius, padding, 4px offset)
- MegaMenu: transparent layer background, panelContainer provides visual style
- Removed isSingleColumn prop — responsive grid handles it

Layout:
- MegaMenu: flex-wrap 2:1 ratio (items + featured), XDSGrid for inner items
- Featured wraps below at narrow widths
- Removed divider div — grid gap provides separation

Shell Lab:
- Independent superheading/subheading toggles for SideNav heading
- All four AppShell variant options

Also:
- useXDSHoverCard: exposed show/hide methods
- Removed isSingleColumn from sandbox mega-menu demo

Part of #565
@cixzhang
cixzhang force-pushed the navi/fix/mega-menu-positioning branch from e022230 to 43afe8e Compare March 15, 2026 21:28
@cixzhang
cixzhang merged commit 33d62b9 into main Mar 15, 2026
13 checks passed
@cixzhang
cixzhang deleted the navi/fix/mega-menu-positioning branch March 15, 2026 21:38
@cixzhang cixzhang mentioned this pull request Mar 15, 2026
52 of 55 tasks
cixzhang added a commit that referenced this pull request Apr 26, 2026
… focus trapping (#622)

Mega menu + menu overhaul addressing #565 findings:

Positioning:
- MegaMenu: anchor to parent <nav> via useXDSPopover
- Menu: anchor to trigger button via useXDSPopover
- Both: slot-aware alignment via TopNavSlotContext
- Removed anchorStretch override and position:relative wrapper requirement

Focus & Keyboard:
- Both use useXDSPopover for focus trapping (tab cycles within menu)
- Menu uses useListFocus for arrow key navigation between items
- MegaMenu uses tab navigation (2D grid, not linear list)
- Click toggles open/closed, locks against hover dismiss
- Escape closes and returns focus to trigger
- Hover as progressive enhancement (show with skipAutoFocus)

Visual:
- Both have chevron with rotation animation
- triggerOpen style for active state (matches XDSTopNavItem selected)
- Menu: popover styling (background, shadow, border-radius, padding, 4px offset)
- MegaMenu: transparent layer background, panelContainer provides visual style
- Removed isSingleColumn prop — responsive grid handles it

Layout:
- MegaMenu: flex-wrap 2:1 ratio (items + featured), XDSGrid for inner items
- Featured wraps below at narrow widths
- Removed divider div — grid gap provides separation

Shell Lab:
- Independent superheading/subheading toggles for SideNav heading
- All four AppShell variant options

Also:
- useXDSHoverCard: exposed show/hide methods
- Removed isSingleColumn from sandbox mega-menu demo

Part of #565
cixzhang added a commit that referenced this pull request Jun 21, 2026
… focus trapping (#622)

Mega menu + menu overhaul addressing #565 findings:

Positioning:
- MegaMenu: anchor to parent <nav> via useXDSPopover
- Menu: anchor to trigger button via useXDSPopover
- Both: slot-aware alignment via TopNavSlotContext
- Removed anchorStretch override and position:relative wrapper requirement

Focus & Keyboard:
- Both use useXDSPopover for focus trapping (tab cycles within menu)
- Menu uses useListFocus for arrow key navigation between items
- MegaMenu uses tab navigation (2D grid, not linear list)
- Click toggles open/closed, locks against hover dismiss
- Escape closes and returns focus to trigger
- Hover as progressive enhancement (show with skipAutoFocus)

Visual:
- Both have chevron with rotation animation
- triggerOpen style for active state (matches XDSTopNavItem selected)
- Menu: popover styling (background, shadow, border-radius, padding, 4px offset)
- MegaMenu: transparent layer background, panelContainer provides visual style
- Removed isSingleColumn prop — responsive grid handles it

Layout:
- MegaMenu: flex-wrap 2:1 ratio (items + featured), XDSGrid for inner items
- Featured wraps below at narrow widths
- Removed divider div — grid gap provides separation

Shell Lab:
- Independent superheading/subheading toggles for SideNav heading
- All four AppShell variant options

Also:
- useXDSHoverCard: exposed show/hide methods
- Removed isSingleColumn from sandbox mega-menu demo

Part of #565
cixzhang added a commit that referenced this pull request Jun 21, 2026
… focus trapping (#622)

Mega menu + menu overhaul addressing #565 findings:

Positioning:
- MegaMenu: anchor to parent <nav> via useXDSPopover
- Menu: anchor to trigger button via useXDSPopover
- Both: slot-aware alignment via TopNavSlotContext
- Removed anchorStretch override and position:relative wrapper requirement

Focus & Keyboard:
- Both use useXDSPopover for focus trapping (tab cycles within menu)
- Menu uses useListFocus for arrow key navigation between items
- MegaMenu uses tab navigation (2D grid, not linear list)
- Click toggles open/closed, locks against hover dismiss
- Escape closes and returns focus to trigger
- Hover as progressive enhancement (show with skipAutoFocus)

Visual:
- Both have chevron with rotation animation
- triggerOpen style for active state (matches XDSTopNavItem selected)
- Menu: popover styling (background, shadow, border-radius, padding, 4px offset)
- MegaMenu: transparent layer background, panelContainer provides visual style
- Removed isSingleColumn prop — responsive grid handles it

Layout:
- MegaMenu: flex-wrap 2:1 ratio (items + featured), XDSGrid for inner items
- Featured wraps below at narrow widths
- Removed divider div — grid gap provides separation

Shell Lab:
- Independent superheading/subheading toggles for SideNav heading
- All four AppShell variant options

Also:
- useXDSHoverCard: exposed show/hide methods
- Removed isSingleColumn from sandbox mega-menu demo

Part of #565
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.

1 participant