Skip to content

refactor(MegaMenu): composed children API + mobile drawer drill-down - #659

Merged
cixzhang merged 5 commits into
mainfrom
navi/refactor/mega-menu-composed
Mar 18, 2026
Merged

cixzhang merged 5 commits into
mainfrom
navi/refactor/mega-menu-composed

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

MegaMenu: Slots API + FeaturedCard + Consistent Mobile Drawer

Refactors XDSTopNavMegaMenu to use ReactNode slots, adds a standard featured card component, and aligns mobile drawer rendering with the rest of the shell.

API

  • items — ReactNode slot for menu items (typically XDSTopNavMegaMenuItem, accepts anything)
  • featured — ReactNode slot for featured content (typically XDSTopNavMegaMenuFeaturedCard, accepts anything)

Components

XDSTopNavMegaMenuItem — real rendering component (was declarative-only):

  • Desktop: popover grid item with large icon, title, description
  • Drawer: navItemStyles.item base with indentation, icon, title, description
  • Supports as prop for custom link components

XDSTopNavMegaMenuFeaturedCard — new standard card:

  • Optional image, title, description, CTA link, children slot
  • Uses theme tokens (no inline styles)

Mobile Drawer

Inline collapsible matching TopNavMenu/SideNavItem patterns:

  • ChevronDown/up toggle, aria-expanded + aria-controls
  • navItemStyles.item base, items show title + description + icon
  • Featured card inside expanded section
  • Animated expand/collapse via grid-template-rows

Removed

  • XDSTopNavMegaMenuGroup, XDSTopNavMegaMenuFeatured (semantic wrappers)
  • parseChildren helper (no child introspection needed)

Docs

TopNav.doc.mjs updated across all 3 locales.


@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 17, 2026
@github-actions

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

TopNav · View in Storybook · 🆕 XDSTopNavMegaMenuItem, XDSTopNavMegaMenuFeaturedCard
Metric Before After Delta
Bundle Size (ESM) N/A 1.2KB N/A
Lines of Code N/A 1492 -
Complexity N/A Very High (92) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.5KB 16.7KB 2.6KB

Accessibility Audit

Status: No accessibility violations detected.


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

navi[bot] and others added 2 commits March 18, 2026 12:32
Refactors XDSTopNavMegaMenu from structured data props to a composed
children API and adds mobile drawer drill-down support.

## Composed Children API

Before:
```tsx
<XDSTopNavMegaMenu label="Products" items={[...]} featured={{...}} />
```

After:
```tsx
<XDSTopNavMegaMenu label="Products">
  <XDSTopNavMegaMenuGroup>
    <XDSTopNavMegaMenuItem title="Analytics" description="Track behavior" icon={<ChartIcon />} href="/analytics" />
  </XDSTopNavMegaMenuGroup>
  <XDSTopNavMegaMenuFeatured>
    {/* any ReactNode */}
  </XDSTopNavMegaMenuFeatured>
</XDSTopNavMegaMenu>
```

New sub-components:
- XDSTopNavMegaMenuGroup — wraps items (renders in XDSGrid)
- XDSTopNavMegaMenuItem — individual item (title, description?, icon?, href?)
- XDSTopNavMegaMenuFeatured — featured area accepting children

Removed props: items, featured, isSingleColumn
Kept props: label, delay, hideDelay, onOpenChange, children

## Mobile Drawer Mode

Uses useXDSTopNavRenderMode() from XDSTopNavRenderContext:
- 'default': existing popover mega menu (unchanged)
- 'mobile-bar': returns null (hidden in compact bar)
- 'drawer': drill-down navigation with back button + item list

Part of #565
Replace drill-down navigation with inline collapsible, consistent with
how TopNavMenu renders in mobile drawers.

Changes:
- Drawer trigger: chevronDown/up (was chevronRight drill-down)
- Drawer items: use navItemStyles.item base + indentation override
- Items show title, description, and icon (was title + icon only)
- Featured card now renders inside the expanded drawer section
- aria-expanded + aria-controls wired up on the toggle button
- Animated expand/collapse via grid-template-rows transition
- Updated tests to reflect new collapsible behavior, added coverage
  for descriptions and featured card in drawer mode

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/refactor/mega-menu-composed branch from d43b1ee to 6c45a5d Compare March 18, 2026 12:41
cixzhang and others added 3 commits March 18, 2026 13:09
…ng MenuItem

Replace composed children API (XDSTopNavMegaMenuGroup, XDSTopNavMegaMenuFeatured)
with direct ReactNode slots on XDSTopNavMegaMenu:

- items: ReactNode slot for menu items (typically XDSTopNavMegaMenuItem)
- featured: ReactNode slot for the featured card

XDSTopNavMegaMenuItem is now a real rendering component that handles both
desktop (popover grid item with icon/title/description) and drawer (navItemStyles
base with indentation) modes via XDSTopNavRenderContext.

Removed:
- XDSTopNavMegaMenuGroup (was a semantic wrapper, no longer needed)
- XDSTopNavMegaMenuFeatured (was a semantic wrapper, no longer needed)
- parseChildren helper (no child introspection needed)

The slots are open ReactNode — consumers can pass XDSTopNavMegaMenuItem
for the standard appearance, or anything else for custom layouts.

Co-authored-by: Navi <[email protected]>
New XDSTopNavMegaMenuFeaturedCard component provides a standard card
with optional image, title, description, and CTA link for the featured
slot. The slot remains open ReactNode for custom content.

Updated:
- TopNav.doc.mjs: all 3 locales updated to slots API (items/featured)
- TopNav/index.ts: export FeaturedCard + props type
- Shell lab, mega-menu sandbox, storybook: use FeaturedCard

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang marked this pull request as ready for review March 18, 2026 14:20
@cixzhang
cixzhang merged commit f44643d into main Mar 18, 2026
11 checks passed
@cixzhang cixzhang mentioned this pull request Mar 18, 2026
52 of 55 tasks
@cixzhang
cixzhang deleted the navi/refactor/mega-menu-composed branch March 20, 2026 16:59
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