Repository navigation
Description
Problem
PRs #377, #378, and #379 reveal a pattern where XDSTopNavMegaMenu uses manual z-index and position: absolute to layer its panel above surrounding content. This led to a cascade of fixes — adding z-index: 100 to nav sections so they wouldn't get covered by the mega menu's backdrop, then removing the backdrop entirely to avoid the complexity.
The root cause: the mega menu panel isn't using the top layer. XDS already has useXDSLayer which uses the Popover API (showPopover() / popover="auto"|"manual"), promoting elements to the browser's top layer. Elements in the top layer render above everything else without needing z-index at all.
Current z-index usage in packages/core/src/
| File | z-index | Purpose |
|---|---|---|
AppShell |
9999 | Skip-to-content link |
AppShell |
100, 101 | Mobile overlay + backdrop |
AppShell |
10 | Sticky header |
TopNavMegaMenu |
100 | Mega menu panel |
| Various inputs | 1 | Internal layering (checkbox, radio, slider, etc.) |
The z-index: 1 cases are fine — they're local stacking within a component. The problem is the 100-level values used for overlays and panels that should be in the top layer instead.
What needs to happen
-
XDSTopNavMegaMenu— Refactor to useuseXDSLayer(or a variant of it) instead of manualposition: absolute+z-index: 100. The panel should be promoted to the top layer via the Popover API. -
XDSAppShellmobile overlay — The mobile side nav overlay and backdrop useposition: fixed+z-index: 100/101. These should also use the top layer (either Popover API or<dialog>withshowModal()). -
Audit remaining z-index > 1 — After fixing the above, audit for any remaining high z-index values that indicate manual stacking instead of top layer usage.
Why this matters
- z-index is fragile. It breaks as soon as a consumer creates a stacking context. Top layer is immune to this.
- Composability. Components shouldn't need to know about each other's z-index values to layer correctly.
- We already have the infrastructure.
useXDSLayerdoes this correctly — the mega menu just didn't use it.
Related PRs
- fix(topnav): mega menu backdrop no longer covers nav items #377 — Added z-index to nav (wrong fix)
- fix(topnav): move mega menu stacking context to nav sections #378 — Moved z-index to nav sections (less wrong, still wrong)
- feat(topnav): unified card appearance for mega menu without backdrop overlay #379 — Removed backdrop, coordinated styles (workaround)
- feat(topnav): unified card appearance for mega menu #356 — Original mega menu unified card appearance
- feat(topnav): add XDSTopNavMegaMenu component #354 — XDSTopNavMegaMenu component
Activity
fix(topnav): use Popover API + CSS anchor positioning for mega menu
refactor(MobileNav): use native <dialog> + showModal() for top layer
cixzhang commentedon Mar 3, 2026
Update: sticky header
z-index: 10in AppShell should also be removed. Sticky positioning already paints above normal flow content — adding z-index just starts the arms race. If page content paints over a sticky header, the fix is removing z-index from that content, not escalating the header.Skip-to-content
z-index: 9999can also go — a popover that shows on focus would use the top layer instead.The only z-index values that should remain in
packages/core/src/are thez-index: 1cases (local internal stacking within a single component, e.g. checkbox overlay on top of its own input).fix(topnav): use top layer for mega menu, reduce z-index in AppShell
refactor(MobileNav): use native <dialog> + showModal() for top layer
fix(topnav): use Popover API + CSS anchor positioning for mega menu (#…
feat(MobileNav): add XDSMobileNav drawer, useMediaQuery hook, and men…
fix(topnav): use Popover API + CSS anchor positioning for mega menu (#…
feat(MobileNav): add XDSMobileNav drawer, useMediaQuery hook, and men…
fix(topnav): use Popover API + CSS anchor positioning for mega menu (#…
feat(MobileNav): add XDSMobileNav drawer, useMediaQuery hook, and men…