Skip to content

feat(AppShell): responsive mobile nav API (#565) - #644

Merged
cixzhang merged 17 commits into
mainfrom
navi/feat/mobile-nav-api
Mar 17, 2026
Merged

cixzhang merged 17 commits into
mainfrom
navi/feat/mobile-nav-api

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

What

New mobileNav prop on XDSAppShell that provides progressive mobile navigation, plus a presentational refactor of XDSMobileNav.

API Shape

type MobileNavConfig = {
  hasToggle?: boolean;     // show auto hamburger (default: true)
  isOpen?: boolean;        // controlled open state
  onOpenChange?: (open: boolean) => void;
  content?: ReactNode;     // custom drawer content
};

mobileNav?: false | MobileNavConfig | ReactNode;

Usage

// 1. Auto — zero config, just works
<XDSAppShell topNav={...} sideNav={...}>

// 2. Controlled state, auto content
<XDSAppShell mobileNav={{ isOpen, onOpenChange }}>

// 3. Custom toggle placement
<XDSAppShell mobileNav={{ hasToggle: false }}>
  <XDSMobileNavToggle />
</XDSAppShell>

// 4. Custom drawer content via config
<XDSAppShell mobileNav={{
  hasToggle: false,
  isOpen,
  onOpenChange,
  content: (
    <XDSMobileNav title="Menu" width={320} side="end">
      <SearchBar />
      <XDSSideNavItem label="Docs" />
    </XDSMobileNav>
  ),
}}>

// 5. ReactNode shorthand — own the drawer
<XDSAppShell mobileNav={<XDSMobileNav title="Menu">...</XDSMobileNav>}>

// 6. Disable
<XDSAppShell mobileNav={false}>

// 7. Standalone (outside AppShell)
<XDSMobileNav isOpen={open} onOpenChange={setOpen} title="Nav">
  ...
</XDSMobileNav>

New Components

  • XDSMobileNavToggle — Hamburger button that reads from AppShell context. Renders nothing above the breakpoint. Can be placed anywhere in the tree.
  • XDSAppShellMobileContext — Shared context: { isMobile, isMobileNavOpen, toggleMobileNav, openMobileNav, closeMobileNav }

XDSMobileNav Changes

isOpen and onOpenChange are now optional. Inside AppShell, state is managed automatically via context. Outside AppShell, provide them as props for standalone use. Both paths are first-class — no deprecation.

Shell Lab

Updated config panel with:

  • Mode selector: Auto / Custom / Disabled
  • Has Toggle: controls auto hamburger visibility
  • Custom mode uses config object with content key wrapping <XDSMobileNav>

Design Decisions

  • Implicit auto: Having topNav or sideNav auto-enables mobile nav at the breakpoint
  • Progressive config: object → ReactNode → false, matching the collapsible pattern
  • SideNav-only minimal top bar: Auto-generated when there is no TopNav below the breakpoint
  • Toggle vs Collapse naming: SideNav uses "collapsible" (visual state — shrinks but stays). MobileNav uses "toggle" (visibility — drawer appears/disappears)
  • Context-based rendering: Future work will have TopNav items read context and adapt

Vibe Test Backing

Tested 4 API variants × 8 prompts (32 agents). This design scored 8/8 high confidence and lowest escape hatches (4 total). Won the programmatic-open case decisively — the object form { isOpen, onOpenChange } gives controlled state without losing auto behavior.

See: #565 (comment)

Still TODO (follow-ups)

  • TopNav items collapsing into the mobile drawer (context-based rendering)
  • TopNavMenu → collapsible section in mobile context
  • Tests for new config object paths
  • MobileNav doc file update

Part of #565


New mobileNav prop on XDSAppShell:
- Implicit auto: having topNav/sideNav auto-enables mobile nav at breakpoint
- Config object: { hasToggle, isOpen, onOpenChange, content } for tuning
- ReactNode: full escape hatch, provide your own <XDSMobileNav>
- false: disable mobile nav entirely

New components:
- XDSMobileNavToggle: context-aware hamburger, renders nothing above breakpoint
- XDSAppShellMobileContext: shared state for mobile nav

For SideNav-only layouts with no TopNav, auto-generates a minimal top bar
with hamburger toggle below the breakpoint.

Part of #565

Co-authored-by: Navi <[email protected]>
@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 · 🆕 XDSAppShellMobileContext
Metric Before After Delta
Bundle Size (ESM) N/A 769B N/A
Lines of Code N/A 499 -
Complexity N/A Very High (73) -
MobileNav · View in Storybook · 🆕 XDSMobileNavToggle
Metric Before After Delta
Bundle Size (ESM) N/A 615B N/A
Lines of Code N/A 306 -
Complexity N/A Very High (33) -
SideNav · View in Storybook · 🆕 XDSSideNavRenderContext
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 1090 -
Complexity N/A Very High (107) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 9.9KB 15.8KB 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

navi[bot] added 13 commits March 17, 2026 05:04
…text

XDSMobileNav now reads open state from XDSAppShellMobileContext when
isOpen/onOpenChange props are omitted. This makes it presentational
when used inside AppShell — state is managed by the parent.

Props still work for standalone use or the ReactNode escape hatch.

Also updates shell lab to use the new mobileNav config API:
- Mode: Auto / Custom / Disabled (was Auto / Custom / None)
- Has Toggle: toggle for auto hamburger visibility
- Custom mode uses config object with content instead of raw state

Co-authored-by: Navi <[email protected]>
The collapse toggle doesn't make sense when the SideNav is inside
the mobile drawer — there's nothing to collapse to. Now reads from
AppShell mobile context and returns null when isMobile is true.

Co-authored-by: Navi <[email protected]>
The breakpoint controls when mobile behavior kicks in, not a SideNav
visual property. Moved from SideNav section to Mobile Nav section,
and only shown when mobile nav is not disabled.

Co-authored-by: Navi <[email protected]>
Shell lab now demos four mobile nav modes:
- Auto: default behavior, AppShell handles everything
- Custom Content: custom drawer with search bar + reordered nav items
- Custom Toggle: auto drawer content, toggle placed in content body
- Disabled: no mobile nav

Custom Content mode shows the config object with content key wrapping
an XDSMobileNav (with side selector). Custom Toggle mode uses
hasToggle: false and renders XDSMobileNavToggle next to the page title.

Co-authored-by: Navi <[email protected]>
New XDSSideNavRenderContext with three modes:
- 'default': full sidebar (desktop inline)
- 'topbar': heading + footerIcons only, horizontal layout (mobile top bar)
- 'drawer': children + topContent + footer only, skip heading/footerIcons

When AppShell renders the auto mobile top bar for SideNav-only layouts
(no TopNav), it wraps the sideNav slot in topbar mode — the SideNav
renders its heading and footer icons horizontally as a top bar, with
the hamburger toggle alongside.

In the mobile drawer, sideNav renders in drawer mode — just the nav
sections and items, since the heading is already shown up top.

Co-authored-by: Navi <[email protected]>
Config content is rendered as-is — if you want a drawer, provide
<XDSMobileNav> in the content. No magic detection or double wrapping.

Co-authored-by: Navi <[email protected]>
New optional header prop on XDSMobileNav. When provided, renders
custom content in the header area instead of the title text.
The close button always renders alongside.

Useful for rendering SideNavHeading, search bars, or other
elements in the drawer header.

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

Simpler approach: SideNav in drawer mode renders itself inside
<XDSMobileNav header={heading}>, passing its heading directly as the
header prop. No portal mechanism needed.

- MobileNav gets header prop (ReactNode) for custom header content
- SideNav drawer mode wraps itself in MobileNav, passes heading
- AppShell just renders sideNav in drawer context — SideNav handles the rest
- Removed XDSMobileNavHeading portal component and header context
- Fixed topbar layout: footer icons use marginInlineStart auto to stay right
  when no heading is present
- Updated tests for new rendering structure

Co-authored-by: Navi <[email protected]>
When the auto mobile top bar has the toggle on the right side,
the drawer should slide from the right (end) to match.

Co-authored-by: Navi <[email protected]>
No consumers yet — safe to flip the default. End (right in LTR)
matches where the toggle sits in the auto mobile top bar.

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

- Header height set to 48px (same as TopNav) for visual consistency
- Default drawer width bumped from 280px to 320px for more breathing room

Co-authored-by: Navi <[email protected]>
Stops scroll chaining from the drawer content into the page behind it.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/mobile-nav-api branch from f3d8ba8 to 919f725 Compare March 17, 2026 06:18
Uses a two-phase open/close cycle:
- Open: showModal() first, then set visualOpen on next frame to trigger
  CSS transitions (slide + backdrop fade)
- Close: clear visualOpen to start animation, delay dialog.close() by
  250ms (10ms for prefers-reduced-motion) so the transition plays

The drawer transform and backdrop opacity transitions were already
defined in CSS — this change wires the timing so the native dialog
lifecycle doesn't kill the close animation.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/mobile-nav-api branch 2 times, most recently from 5f6dd73 to 2c9c4b2 Compare March 17, 2026 12:49
Keeps the close animation: when isOpen goes false, the CSS transition
plays (drawer slides out, backdrop fades) and dialog.close() is delayed
250ms (10ms for prefers-reduced-motion) so the animation completes.

Entry animation deferred to a follow-up — needs more investigation
with @starting-style and the dialog positioning model.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/mobile-nav-api branch from 2c9c4b2 to cdd7679 Compare March 17, 2026 12:51
Drawer is now full viewport width by default, capped at the
configured width (320px). On small screens, the drawer fills
the screen instead of leaving a gap.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang marked this pull request as ready for review March 17, 2026 13:03
@cixzhang
cixzhang merged commit 59d9993 into main Mar 17, 2026
11 checks passed
@cixzhang
cixzhang deleted the navi/feat/mobile-nav-api branch March 17, 2026 13:04
@cixzhang cixzhang mentioned this pull request Mar 17, 2026
52 of 55 tasks
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