Skip to content

Rework mega menu: remove XDSTopNavMegaMenu, compose with XDSPopover instead #414

Closed

Description

@cixzhang

Problem

XDSTopNavMegaMenu and XDSTopNavMenu have API issues:

  1. Data props instead of composition — items: Array<{title, description, icon, href}> and featured: {image, title, ...} bake layout into the component. Consumers can't compose arbitrary content.
  2. Hover-only interaction — No click path, broken on touch, limited keyboard support. XDSTopNavMenu uses useXDSHoverCard which puts content in tab order but has no focus trap or arrow key navigation.
  3. Wrapper div boilerplate — XDSTopNavMegaMenu requires consumers to wrap XDSTopNav in a position: relative div for full-width positioning.
  4. Duplicated trigger styling — Both components render their own trigger button that duplicates XDSTopNavItem styling.
  5. No controlled state — Neither supports isShown/onToggle for controlled open/close. Vibe test showed both agents abandoned these components entirely for controlled scenarios (mm-7).
  6. z-index stacking — XDSTopNavMegaMenu used manual z-index: 100 instead of the top layer, causing the cascade of fixes in fix(topnav): mega menu backdrop no longer covers nav items #377/fix(topnav): move mega menu stacking context to nav sections #378/feat(topnav): unified card appearance for mega menu without backdrop overlay #379.
  7. XDSDropdownMenuItem naming — The menu item component is scoped to "Dropdown" but works in nav menus too.

Proposal: Rework both components + introduce XDSMenuItem

Keep both components but make them compositional. Each encodes the correct ARIA pattern while delegating layout to the consumer.

XDSTopNavMenu — role="menu" pattern

A nav item that opens a dropdown menu. Click-triggered. Uses XDSPopover internally for top layer, focus trap, light dismiss, and keyboard support.

<XDSTopNav
  startContent={
    <>
      <XDSTopNavItem label="Home" href="/" isSelected />
      <XDSTopNavMenu label="Products">
        <XDSMenuItem label="Analytics" description="Track behavior" icon="chart" href="/analytics" />
        <XDSMenuItem label="Platform" description="Build at scale" icon="layers" href="/platform" />
        <XDSMenuItem label="Security" description="Enterprise protection" icon="shield" href="/security" />
      </XDSTopNavMenu>
      <XDSTopNavItem label="Pricing" href="/pricing" />
    </>
  }
/>

Changes from current:

  • children slot replaces items data prop — accepts XDSMenuItem children
  • Click-triggered (via XDSPopover) instead of hover-only
  • role="menu" on container, role="menuitem" on each XDSMenuItem
  • Focus trap, Escape to close, light dismiss — all from XDSPopover
  • Trigger styled as XDSTopNavItem (no duplicated styling)
  • label prop stays (static trigger text — does NOT update with selection, confirmed current behavior)

XDSTopNavMegaMenu — button + role="dialog" pattern

A nav item that opens a full-width panel for rich content. Uses role="dialog" because mega menu content is mixed (links, images, headings) — not a flat menu.

<XDSTopNav
  startContent={
    <XDSTopNavMegaMenu label="Solutions">
      <XDSHStack gap="space6">
        <XDSGrid columns={2} gap="space2">
          <XDSMenuItem label="Enterprise" description="Scale solutions" href="/enterprise" />
          <XDSMenuItem label="Startups" description="Get started fast" href="/startups" />
          <XDSMenuItem label="Developers" description="APIs and tools" href="/developers" />
          <XDSMenuItem label="Partners" description="Join the ecosystem" href="/partners" />
        </XDSGrid>
        <XDSVStack gap="space3">
          <XDSHeading level={3}>What's new</XDSHeading>
          <XDSText>Explore the latest platform updates.</XDSText>
          <XDSLink href="/blog">Learn more</XDSLink>
        </XDSVStack>
      </XDSHStack>
    </XDSTopNavMegaMenu>
  }
/>

Changes from current:

  • children slot replaces items + featured data props — compose any layout
  • Auto-anchors to nearest XDSTopNav ancestor — no wrapper div needed, no anchorRef boilerplate
  • Click-triggered instead of hover-only
  • role="dialog" (rich content, not a flat menu)
  • Full-width by default (anchored to nav), with optional width prop

XDSMenuItem — shared menu item component

Rename XDSDropdownMenuItem → XDSMenuItem. Works inside any menu container.

import {XDSMenuItem} from '@xds/core/Menu';

// In a dropdown menu
<XDSDropdownMenu button={<XDSButton label="Actions" />}>
  <XDSMenuItem label="Edit" icon="edit" />
  <XDSMenuItem label="Delete" icon="trash" variant="destructive" />
</XDSDropdownMenu>

// In a nav menu
<XDSTopNavMenu label="Products">
  <XDSMenuItem label="Analytics" description="Track behavior" icon="chart" href="/analytics" />
</XDSTopNavMenu>

// In a mega menu
<XDSTopNavMegaMenu label="Solutions">
  <XDSMenuItem label="Enterprise" description="Scale solutions" href="/enterprise" />
</XDSTopNavMegaMenu>
  • Same props: label, description, icon, href, onClick, variant
  • Container handles ARIA roles (role="menuitem" applied by the menu container)
  • XDSDropdownMenuItem kept as deprecated re-export for backward compat
  • Moves to @xds/core/Menu

Migration

Before After
XDSTopNavMenu label="X" items={[...]} XDSTopNavMenu label="X"> <XDSMenuItem .../> </XDSTopNavMenu>
XDSTopNavMegaMenu label="X" items={[...]} featured={{...}} XDSTopNavMegaMenu label="X"> <composed content> </XDSTopNavMegaMenu>
div style={{position:"relative"}} wrapper Gone — auto-anchoring
XDSDropdownMenuItem XDSMenuItem (deprecated re-export available)
Hover-only interaction Click-triggered with focus trap

Vibe test evidence

Mega menu API test (8 prompts × 2 configs)

  • Composed pattern was correct on all 8 prompts (real a11y, natural layouts)
  • Monolithic was more concise on 2/8 prompts but shoehorned layouts and hallucinated a11y
  • Both agents abandoned nav menu components for controlled state (mm-7) — confirms data props aren't needed for trigger updates
  • XDSTopNavMegaMenu only used 2/8 times even when available

XDSMenuItem rename test (5 prompts × 2 configs)

  • Zero confusion — XDSMenuItem used correctly in XDSDropdownMenu, XDSTopNavMenu, and both on the same page
  • Generic name reads naturally in every context
  • Current name (XDSDropdownMenuItem) already crosses context boundaries without issues

Full results: memory/vibe-test-mega-menu-results.md

Related

Activity

  1. added
    enhancement
    on Mar 3, 2026
  2. cixzhang commented on Mar 3, 2026

    @cixzhang
    ContributorAuthor

    Correction: Layout components in examples

    The issue examples reference XDSColumns which doesn't exist. The actual layout primitives are:

    • XDSHStack / XDSVStack — flex-based stacks
    • XDSGrid + XDSGridSpan — CSS grid with columns, minChildWidth, gap

    Updated mega menu example using real components:

    // Full-width mega menu
    <XDSPopover
      anchorRef={navWrapperRef}
      label="Products"
      placement="below"
      width="anchor"
      content={
        <XDSHStack gap="space6">
          <XDSGrid columns={2} gap="space2" xstyle={{flex: 1}}>
            <NavMenuItem icon={<ChartIcon />} title="Analytics" href="/analytics" />
            <NavMenuItem icon={<CodeIcon />} title="Dev Tools" href="/dev" />
            <NavMenuItem icon={<ShieldIcon />} title="Security" href="/security" />
            <NavMenuItem icon={<ZapIcon />} title="Automation" href="/automation" />
          </XDSGrid>
          <XDSVStack gap="space4" xstyle={{width: 280}}>
            <XDSHeading level={3}>What's new</XDSHeading>
            <XDSText>Explore the latest features...</XDSText>
            <XDSLink href="/blog">Learn more</XDSLink>
          </XDSVStack>
        </XDSHStack>
      }
    >
      <XDSTopNavItem label="Products" />
    </XDSPopover>
  3. cixzhang commented on Mar 3, 2026

    @cixzhang
    ContributorAuthor

    Refined spec (from vibe test findings + Cindy feedback)

    Keep both components, but make them compositional

    The vibe test showed monolithic components are only useful for 2/8 nav scenarios, but Cindy points out they still earn their existence by encoding the right ARIA pattern — that's semantic, not just convenience.

    XDSTopNavMenu — role="menu" / role="menuitem" pattern

    • Trigger is an XDSTopNavItem-styled button with aria-haspopup="menu"
    • Content is a children slot (not items data prop) — consumer composes menu items
    • Uses XDSPopover internally for layering (top layer, focus trap, light dismiss)
    • Provides role="menu" on the container and expects role="menuitem" on children
    • Keeps label prop for the trigger text (static — does NOT update with selection, confirmed both current components use static labels)

    XDSTopNavMegaMenu — button + role="dialog" pattern

    • Trigger is an XDSTopNavItem-styled button
    • Content is a children slot (not items/featured data props)
    • Uses XDSPopover internally with auto-anchoring to nearest XDSTopNav ancestor — no wrapper div needed, no anchorRef boilerplate
    • role="dialog" since mega menu content is rich/mixed (not a flat menu)
    • Full-width by default (anchored to nav), with width prop for custom sizing

    Auto-anchoring eliminates wrapper div boilerplate

    Current composed pattern requires:

    const navRef = useRef(null);
    <div ref={navRef}>
      <XDSTopNav .../>
      <XDSPopover anchorRef={navRef} width="anchor" .../>
    </div>

    With auto-anchoring, XDSTopNavMegaMenu walks up to find its XDSTopNav ancestor (which already uses forwardRef) and anchors to it automatically:

    <XDSTopNav
      startContent={
        <XDSTopNavMegaMenu label="Solutions">
          <XDSHStack gap="space6">
            <XDSGrid columns={2} gap="space2">...</XDSGrid>
            <PromoCard />
          </XDSHStack>
        </XDSTopNavMegaMenu>
      }
    />

    No ref, no wrapper div, no width="anchor".

    What changes from original #414

    Original proposal Refined
    Delete both components Keep both, rework internals
    Pure XDSPopover composition Components encode ARIA patterns + auto-anchor
    items data prop children slot (composition)
    featured data prop Gone — compose your own layout
    Consumer manages anchorRef Auto-anchor to XDSTopNav ancestor
    width="anchor" on XDSPopover Still useful as a general feature, but mega menu handles it internally

    Vibe test evidence

    • Composed pattern was correct on all 8 prompts (real a11y, natural layouts)
    • Monolithic was more concise on 2/8 prompts but shoehorned layouts (mm-5) and hallucinated a11y (mm-8)
    • Both agents abandoned nav menu components for controlled state (mm-7) — confirms items data prop isn't needed for trigger label updates
    • Full results: memory/vibe-test-mega-menu-results.md
  4. cixzhang commented on Mar 3, 2026

    @cixzhang
    ContributorAuthor

    XDSMenuItem — shared menu item component

    Vibe tested renaming XDSDropdownMenuItem → XDSMenuItem across 5 prompts × 2 configs. Zero confusion. The generic name works naturally in every context.

    What changes

    • Rename XDSDropdownMenuItem → XDSMenuItem — moves from @xds/core/DropdownMenu to @xds/core/Menu
    • XDSMenuItem works inside both XDSDropdownMenu and XDSTopNavMenu
    • Keep XDSDropdownMenuItem as a deprecated re-export for backward compat

    API

    import {XDSMenuItem} from '@xds/core/Menu';
    
    // In a dropdown menu
    <XDSDropdownMenu button={<XDSButton label="Actions" />}>
      <XDSMenuItem label="Edit" icon="edit" />
      <XDSMenuItem label="Delete" icon="trash" variant="destructive" />
    </XDSDropdownMenu>
    
    // In a nav menu
    <XDSTopNavMenu label="Products">
      <XDSMenuItem label="Analytics" description="Track behavior" icon="chart" href="/analytics" />
      <XDSMenuItem label="Platform" description="Build at scale" icon="layers" href="/platform" />
    </XDSTopNavMenu>

    Same component, same props, different containers. The container handles the ARIA pattern (role="menu" on the list, role="menuitem" on each item).

    Vibe test evidence

    Prompt Context Result
    mi-1 Table row actions (XDSDropdownMenu) ✅ XDSMenuItem used correctly
    mi-3 Nav dropdown (XDSTopNavMenu) ✅ XDSMenuItem used correctly
    mi-4 Both on same page ✅ Same XDSMenuItem in both menus
    mi-5 Sort selector ✅ Correctly avoided XDSMenuItem (used items array)

    Full results: memory/vibe-test-mega-menu-results.md

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

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions