Skip to content

Eliminate z-index stacking — use top layer (Popover API) for all overlays #411

Closed

Description

@cixzhang

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

  1. XDSTopNavMegaMenu — Refactor to use useXDSLayer (or a variant of it) instead of manual position: absolute + z-index: 100. The panel should be promoted to the top layer via the Popover API.

  2. XDSAppShell mobile overlay — The mobile side nav overlay and backdrop use position: fixed + z-index: 100/101. These should also use the top layer (either Popover API or <dialog> with showModal()).

  3. 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. useXDSLayer does this correctly — the mega menu just didn't use it.

Related PRs

Activity

  1. added
    bug
    on Mar 3, 2026
  2. added 2 commits that reference this issue on Mar 3, 2026
    a575117
    7451643
  3. cixzhang commented on Mar 3, 2026

    @cixzhang
    ContributorAuthor

    Update: sticky header z-index: 10 in 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: 9999 can 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 the z-index: 1 cases (local internal stacking within a single component, e.g. checkbox overlay on top of its own input).

  4. added 2 commits that reference this issue on Mar 3, 2026
    3e38f53
    c228a00
  5. added 2 commits that reference this issue on Apr 26, 2026
    d480b15
    2de6667
  6. added 4 commits that reference this issue on Jun 21, 2026
    21997a4
    1ebd42d
    0ca3929
    904e6f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions