Skip to content

feat(TopNav): mobile responsive rendering (#565) - #652

Merged
cixzhang merged 3 commits into
mainfrom
navi/feat/topnav-mobile
Mar 17, 2026
Merged

cixzhang merged 3 commits into
mainfrom
navi/feat/topnav-mobile

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

What

TopNav items now collapse into a mobile drawer below the breakpoint, matching the SideNav pattern.

How it works

Same context-based rendering strategy as SideNav. TopNav reads XDSTopNavRenderContext and adapts:

  • default — full top bar (desktop)
  • mobile-bar — heading + endContent + hamburger toggle, hides nav items
  • drawer — nav items rendered vertically inside <XDSMobileNav>

XDSTopNavItem also reads the context — in drawer mode it renders as a full-width SideNavItem-style list element with vertical layout and tap targets.

AppShell integration

  • Wraps topNav in mobile-bar context when below the breakpoint
  • Renders topNav in drawer context for the mobile drawer
  • Breakpoint detection now triggers on hasTopNav (not just hasSideNav)
  • TopNav handles its own <XDSMobileNavToggle> in mobile-bar mode
  • Only shows toggle when there are collapsible items (startContent/centerContent)

Cases handled

Config Desktop Mobile top bar Mobile drawer
TopNav + SideNav Full TopNav + SideNav Heading + endContent + toggle TopNav items drawer + SideNav drawer
TopNav only Full TopNav Heading + endContent + toggle TopNav items drawer
TopNav (endContent only) Full TopNav Full TopNav (no toggle) No drawer

Not in this PR

  • TopNavMenu → collapsible section in mobile (follow-up)
  • TopNavMegaMenu mobile rendering (follow-up)
  • Shell lab integration for TopNav mobile modes

Part of #565


@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

AppShell · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 801B N/A
Lines of Code N/A 540 -
Complexity N/A Very High (83) -
SideNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 1103 -
Complexity N/A Very High (108) -
TopNav · View in Storybook · 🆕 XDSTopNavRenderContext
Metric Before After Delta
Bundle Size (ESM) N/A 1011B N/A
Lines of Code N/A 1196 -
Complexity N/A Very High (75) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.0KB 16.0KB 2.5KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

XDSSideNav - 1 issue(s)
  • 🟠 serious: Ensure links have discernible text
    • Rule: link-name · Affects 1/8 stories · Learn more
    • WCAG: 2.4.4, 4.1.2 (Level A)

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

@cixzhang
cixzhang marked this pull request as ready for review March 17, 2026 14:52
navi[bot] added 3 commits March 17, 2026 14:57
…tching

TopNav now supports three render modes via XDSTopNavRenderContext:
- default: full top bar (desktop)
- mobile-bar: heading + endContent + toggle, hides nav items
- drawer: nav items rendered vertically inside XDSMobileNav

XDSTopNavItem adapts in drawer mode — renders as a SideNavItem-style
vertical list element with full-width tap targets.

AppShell integration:
- Wraps topNav in mobile-bar context when below breakpoint
- Renders topNav in drawer context for TopNav-only layouts
- Breakpoint detection now triggers on hasTopNav (not just hasSideNav)
- TopNav handles its own XDSMobileNavToggle in mobile-bar mode

Handles all cases:
- TopNav + SideNav: TopNav simplifies to heading+endContent+toggle,
  TopNav items go to a separate drawer (SideNav has its own)
- TopNav only: TopNav renders its own drawer with items
- No collapsible content: no toggle shown, no drawer rendered

Co-authored-by: Navi <[email protected]>
When both TopNav and SideNav exist, renders a single mobile drawer
instead of two separate ones. TopNav owns the drawer and SideNav
content is passed via XDSTopNavMobileContentContext.

- New 'drawer-content' mode for SideNav: renders items without
  XDSMobileNav wrapper (used when nested inside TopNav's drawer)
- AppShell passes SideNav (in drawer-content mode) as context to
  TopNav when both exist
- TopNav drawer renders its items first, then SideNav content below
- TopNav heading goes to the drawer header

Cases:
- TopNav+SideNav: one drawer (TopNav owns, SideNav items below)
- TopNav only: one drawer (TopNav owns)
- SideNav only: one drawer (SideNav owns, unchanged)

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/topnav-mobile branch from dfe57cb to 7fd92e4 Compare March 17, 2026 14:58
@cixzhang cixzhang mentioned this pull request Mar 17, 2026
52 of 55 tasks
@cixzhang
cixzhang merged commit f128846 into main Mar 17, 2026
11 checks passed
@cixzhang
cixzhang deleted the navi/feat/topnav-mobile branch March 17, 2026 15:36
cixzhang added a commit that referenced this pull request Apr 26, 2026
* feat(TopNav): mobile responsive rendering with context-based mode switching

TopNav now supports three render modes via XDSTopNavRenderContext:
- default: full top bar (desktop)
- mobile-bar: heading + endContent + toggle, hides nav items
- drawer: nav items rendered vertically inside XDSMobileNav

XDSTopNavItem adapts in drawer mode — renders as a SideNavItem-style
vertical list element with full-width tap targets.

AppShell integration:
- Wraps topNav in mobile-bar context when below breakpoint
- Renders topNav in drawer context for TopNav-only layouts
- Breakpoint detection now triggers on hasTopNav (not just hasSideNav)
- TopNav handles its own XDSMobileNavToggle in mobile-bar mode

Handles all cases:
- TopNav + SideNav: TopNav simplifies to heading+endContent+toggle,
  TopNav items go to a separate drawer (SideNav has its own)
- TopNav only: TopNav renders its own drawer with items
- No collapsible content: no toggle shown, no drawer rendered

Co-authored-by: Navi <[email protected]>

* feat(AppShell): single combined mobile drawer for TopNav + SideNav

When both TopNav and SideNav exist, renders a single mobile drawer
instead of two separate ones. TopNav owns the drawer and SideNav
content is passed via XDSTopNavMobileContentContext.

- New 'drawer-content' mode for SideNav: renders items without
  XDSMobileNav wrapper (used when nested inside TopNav's drawer)
- AppShell passes SideNav (in drawer-content mode) as context to
  TopNav when both exist
- TopNav drawer renders its items first, then SideNav content below
- TopNav heading goes to the drawer header

Cases:
- TopNav+SideNav: one drawer (TopNav owns, SideNav items below)
- TopNav only: one drawer (TopNav owns)
- SideNav only: one drawer (SideNav owns, unchanged)

Co-authored-by: Navi <[email protected]>

* fix: add spacing before injected SideNav content in mobile drawer

Co-authored-by: Navi <[email protected]>

---------

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* feat(TopNav): mobile responsive rendering with context-based mode switching

TopNav now supports three render modes via XDSTopNavRenderContext:
- default: full top bar (desktop)
- mobile-bar: heading + endContent + toggle, hides nav items
- drawer: nav items rendered vertically inside XDSMobileNav

XDSTopNavItem adapts in drawer mode — renders as a SideNavItem-style
vertical list element with full-width tap targets.

AppShell integration:
- Wraps topNav in mobile-bar context when below breakpoint
- Renders topNav in drawer context for TopNav-only layouts
- Breakpoint detection now triggers on hasTopNav (not just hasSideNav)
- TopNav handles its own XDSMobileNavToggle in mobile-bar mode

Handles all cases:
- TopNav + SideNav: TopNav simplifies to heading+endContent+toggle,
  TopNav items go to a separate drawer (SideNav has its own)
- TopNav only: TopNav renders its own drawer with items
- No collapsible content: no toggle shown, no drawer rendered

Co-authored-by: Navi <[email protected]>

* feat(AppShell): single combined mobile drawer for TopNav + SideNav

When both TopNav and SideNav exist, renders a single mobile drawer
instead of two separate ones. TopNav owns the drawer and SideNav
content is passed via XDSTopNavMobileContentContext.

- New 'drawer-content' mode for SideNav: renders items without
  XDSMobileNav wrapper (used when nested inside TopNav's drawer)
- AppShell passes SideNav (in drawer-content mode) as context to
  TopNav when both exist
- TopNav drawer renders its items first, then SideNav content below
- TopNav heading goes to the drawer header

Cases:
- TopNav+SideNav: one drawer (TopNav owns, SideNav items below)
- TopNav only: one drawer (TopNav owns)
- SideNav only: one drawer (SideNav owns, unchanged)

Co-authored-by: Navi <[email protected]>

* fix: add spacing before injected SideNav content in mobile drawer

Co-authored-by: Navi <[email protected]>

---------

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* feat(TopNav): mobile responsive rendering with context-based mode switching

TopNav now supports three render modes via XDSTopNavRenderContext:
- default: full top bar (desktop)
- mobile-bar: heading + endContent + toggle, hides nav items
- drawer: nav items rendered vertically inside XDSMobileNav

XDSTopNavItem adapts in drawer mode — renders as a SideNavItem-style
vertical list element with full-width tap targets.

AppShell integration:
- Wraps topNav in mobile-bar context when below breakpoint
- Renders topNav in drawer context for TopNav-only layouts
- Breakpoint detection now triggers on hasTopNav (not just hasSideNav)
- TopNav handles its own XDSMobileNavToggle in mobile-bar mode

Handles all cases:
- TopNav + SideNav: TopNav simplifies to heading+endContent+toggle,
  TopNav items go to a separate drawer (SideNav has its own)
- TopNav only: TopNav renders its own drawer with items
- No collapsible content: no toggle shown, no drawer rendered


* feat(AppShell): single combined mobile drawer for TopNav + SideNav

When both TopNav and SideNav exist, renders a single mobile drawer
instead of two separate ones. TopNav owns the drawer and SideNav
content is passed via XDSTopNavMobileContentContext.

- New 'drawer-content' mode for SideNav: renders items without
  XDSMobileNav wrapper (used when nested inside TopNav's drawer)
- AppShell passes SideNav (in drawer-content mode) as context to
  TopNav when both exist
- TopNav drawer renders its items first, then SideNav content below
- TopNav heading goes to the drawer header

Cases:
- TopNav+SideNav: one drawer (TopNav owns, SideNav items below)
- TopNav only: one drawer (TopNav owns)
- SideNav only: one drawer (SideNav owns, unchanged)


* fix: add spacing before injected SideNav content in mobile drawer


---------
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