Repository navigation
fix(topnav): use Popover API + CSS anchor positioning for mega menu - #412
Conversation
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsAppShell · View in Storybook
TopNav · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Component PreviewsIncludes interactive hover previews as animated GIFs. XDSAppShellTop Nav With Side NavScreenshot: Interaction Preview: (view video) View in Storybook · XDSTopNavDefaultScreenshot: Interaction Preview: (view video) View in Storybook · Centered With Start ContentScreenshot: View in Storybook · Center Content Without EndScreenshot: View in Storybook · Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
| 'use client'; | ||
|
|
||
| import {useCallback, useEffect, useRef, useState, type ReactNode} from 'react'; | ||
| import { |
There was a problem hiding this comment.
This isn't using useXDSLayer when I expected it to. That should probably eliminate most of the extra behaviors we needed to add around mouse event handling. More ideally though, we should be using useXDSPopover or XDSPopover with custom trigger and anchor refs.
| borderBottomRightRadius: radiusVars['--radius-container'], | ||
| // Shadow wraps the panel; the wrapper handles the nav bar's card chrome. | ||
| // Together they create a unified card appearance without a backdrop overlay. | ||
| boxShadow: `0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08)`, |
There was a problem hiding this comment.
This should use elevationVars.
| borderWidth: 0, | ||
| borderStyle: 'none', | ||
| // Visual styles | ||
| backgroundColor: colorVars['--color-surface'], |
There was a problem hiding this comment.
Since this is a popover, it should be using the popover background which is slightly different in dark mode.
Mega menu: - Use useXDSLayer (Popover API + CSS anchor positioning) instead of manual position: absolute + z-index: 100 - Panel promoted to top layer — no z-index needed - CSS anchor positioning via layer.ref() on nearest positioned ancestor - Use colorVars['--color-popover'] (correct dark mode) and elevationVars['--elevation-menu'] (semantic token) - Animation via :popover-open + @starting-style + allow-discrete - Mouse event handlers on panel for top-layer hover bridging AppShell: - Sticky header z-index: 10 → 1 (only needs to beat auto) Closes #411
a575117 to
3e38f53
Compare
|
Can we have proper stories for the mega menu and top nav menu so they can be inspected for regressions? |
Add dedicated stories for XDSTopNavMenu and XDSTopNavMegaMenu so they can be inspected for regressions in the Storybook preview. Stories: - Default: Single nav menu with 4 items (icon + title + description) - Multiple Menus: Two nav menus side by side - Mega Menu: Full-width with items grid + featured content - Mega Menu (Simple): Single column, no featured content
|
Added dedicated Storybook stories for XDSTopNavMenu and XDSTopNavMegaMenu:
These will show up in the Storybook preview once CI deploys. |
…412) * fix(topnav): use top layer for mega menu, reduce z-index in AppShell Mega menu: - Use useXDSLayer (Popover API + CSS anchor positioning) instead of manual position: absolute + z-index: 100 - Panel promoted to top layer — no z-index needed - CSS anchor positioning via layer.ref() on nearest positioned ancestor - Use colorVars['--color-popover'] (correct dark mode) and elevationVars['--elevation-menu'] (semantic token) - Animation via :popover-open + @starting-style + allow-discrete - Mouse event handlers on panel for top-layer hover bridging AppShell: - Sticky header z-index: 10 → 1 (only needs to beat auto) Closes #411 * feat(storybook): add TopNavMenu and TopNavMegaMenu stories Add dedicated stories for XDSTopNavMenu and XDSTopNavMegaMenu so they can be inspected for regressions in the Storybook preview. Stories: - Default: Single nav menu with 4 items (icon + title + description) - Multiple Menus: Two nav menus side by side - Mega Menu: Full-width with items grid + featured content - Mega Menu (Simple): Single column, no featured content
…412) * fix(topnav): use top layer for mega menu, reduce z-index in AppShell Mega menu: - Use useXDSLayer (Popover API + CSS anchor positioning) instead of manual position: absolute + z-index: 100 - Panel promoted to top layer — no z-index needed - CSS anchor positioning via layer.ref() on nearest positioned ancestor - Use colorVars['--color-popover'] (correct dark mode) and elevationVars['--elevation-menu'] (semantic token) - Animation via :popover-open + @starting-style + allow-discrete - Mouse event handlers on panel for top-layer hover bridging AppShell: - Sticky header z-index: 10 → 1 (only needs to beat auto) Closes #411 * feat(storybook): add TopNavMenu and TopNavMegaMenu stories Add dedicated stories for XDSTopNavMenu and XDSTopNavMegaMenu so they can be inspected for regressions in the Storybook preview. Stories: - Default: Single nav menu with 4 items (icon + title + description) - Multiple Menus: Two nav menus side by side - Mega Menu: Full-width with items grid + featured content - Mega Menu (Simple): Single column, no featured content
…412) * fix(topnav): use top layer for mega menu, reduce z-index in AppShell Mega menu: - Use useXDSLayer (Popover API + CSS anchor positioning) instead of manual position: absolute + z-index: 100 - Panel promoted to top layer — no z-index needed - CSS anchor positioning via layer.ref() on nearest positioned ancestor - Use colorVars['--color-popover'] (correct dark mode) and elevationVars['--elevation-menu'] (semantic token) - Animation via :popover-open + @starting-style + allow-discrete - Mouse event handlers on panel for top-layer hover bridging AppShell: - Sticky header z-index: 10 → 1 (only needs to beat auto) Closes #411 * feat(storybook): add TopNavMenu and TopNavMegaMenu stories Add dedicated stories for XDSTopNavMenu and XDSTopNavMegaMenu so they can be inspected for regressions in the Storybook preview. Stories: - Default: Single nav menu with 4 items (icon + title + description) - Multiple Menus: Two nav menus side by side - Mega Menu: Full-width with items grid + featured content - Mega Menu (Simple): Single column, no featured content
Problem
The mega menu panel used manual
position: absolute+z-index: 100for layering, which triggered a cascade of z-index band-aids (#377, #378, #379). This is fragile — any consumer stacking context can break it.XDS already has proper top layer infrastructure (
useXDSLayeruses the Popover API), but the mega menu bypassed it entirely.Fix
Replace manual z-index stacking with the browser's top layer:
Popover API — Panel uses
popover="manual"+showPopover()/hidePopover(). Promoted to the top layer automatically — renders above everything without z-index.CSS anchor positioning — Panel anchors to the nearest positioned ancestor (the nav wrapper div) using
position-anchor+anchor()functions. Replacesposition: absolute+top: 100%+left: 0+right: 0.Mouse event bridging — Since top layer elements are outside the DOM hierarchy for mouse events, added
onMouseEnter/onMouseLeaveon the panel itself. Without this, mousing from trigger → panel would fireonMouseLeaveon the wrapper and close the menu.Popover toggle sync — Listens for native
toggleevents to sync popover state back to React.What changed
position: absolute+z-index: 100popover="manual"(top layer)position: relativewrapper for positioningposition: relativewrapper as CSS anchorz-index audit (after this PR)
No z-index values remain in
XDSTopNavMegaMenu. Remaining z-index inpackages/core/src/:Test Plan
Closes #411
Related