Skip to content

feat(MobileNav): add XDSMobileNav drawer, useMediaQuery hook, and menu icon - #341

Merged
cixzhang merged 8 commits into
mainfrom
navi/feat/mobile-nav
Mar 4, 2026
Merged

cixzhang merged 8 commits into
mainfrom
navi/feat/mobile-nav

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Summary

Adds XDSMobileNav — a slide-out drawer overlay for mobile navigation. The mobile counterpart to XDSSideNav, accepting the same children (XDSSideNavSection, XDSSideNavItem, or any ReactNode).

Also ships:

  • useMediaQuery hook — SSR-safe, used for responsive patterns
  • menu icon — hamburger icon added to the semantic icon set (default + neutral themes)

API

<XDSMobileNav
  isOpen={isOpen}
  onClose={() => setIsOpen(false)}
  title="Navigation"
>
  <XDSSideNavSection title="Main">
    <XDSSideNavItem label="Home" icon={HomeIcon} isSelected href="/" />
    <XDSSideNavItem label="Settings" icon={SettingsIcon} href="/settings" />
  </XDSSideNavSection>
</XDSMobileNav>

Vibe Test Results

Ran a focused vibe test (8 prompts, XDS vs baseline/Tailwind):

Metric XDS Baseline
Discovery rate 8/8 (100%) 2/8 (25%)
Avg lines of code 173 270
Code reduction -35% —

Every LLM agent found XDSMobileNav, read the docs, and composed it correctly. Baseline agents mostly built custom drawers from scratch (~50 lines of boilerplate each).

What's Included

File Purpose
packages/core/src/MobileNav/XDSMobileNav.tsx Slide-out drawer component
packages/core/src/MobileNav/XDSMobileNav.test.tsx 12 unit tests
packages/core/src/MobileNav/README.md Full documentation
packages/core/src/hooks/useMediaQuery.ts SSR-safe media query hook
apps/storybook/stories/MobileNav.stories.tsx 6 stories

Accessibility

  • role="dialog" + aria-modal="true"
  • Focus trap via useFocusTrap hook
  • Escape key dismissal
  • Backdrop click dismissal
  • Body scroll lock
  • Focus restore on close
  • prefers-reduced-motion respected (near-instant transitions)
  • RTL-aware transforms ([dir="rtl"] flips slide direction)

Test Plan

  • 12 unit tests pass (open/close, escape, backdrop, a11y, data-testid)
  • Full test suite: 60 files, 1019 tests pass
  • Build passes (core + both themes)
  • Lint clean (0 errors)
  • Vibe tested: 8 prompts, 100% discovery

Closes #329


Crafted with care by Navi

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

github-actions Bot commented Feb 25, 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.

New Components

MobileNav · View in Storybook
Metric Value
Bundle Size (ESM) 403B
Bundle Size (CJS) 517B
Lines of Code 244
Source Files 2
Complexity High (25)
Exports XDSMobileNav
Props Count N/A
Has Tests Yes
Has Stories Yes

Modified Components

AppShell · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 497B N/A
Lines of Code N/A 297 -
Complexity N/A Very High (32) -
Icon · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 223B N/A
Lines of Code N/A 292 -
Complexity N/A Medium (8) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 8.3KB 13.4KB 2.1KB

Accessibility Audit

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

XDSIcon - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Component Previews

Includes interactive hover previews as animated GIFs.

XDSAppShell

Top Nav With Side Nav

Screenshot:

Top Nav With Side Nav

Interaction Preview: (view video)

Top Nav With Side Nav interaction

View in Storybook · core-xdsappshell--top-nav-with-side-nav

Side Nav Only

Screenshot:

Side Nav Only

View in Storybook · core-xdsappshell--side-nav-only

Top Nav Only

Screenshot:

Top Nav Only

View in Storybook · core-xdsappshell--top-nav-only

Full Featured

Screenshot:

Full Featured

View in Storybook · core-xdsappshell--full-featured

Auto Height

Screenshot:

Auto Height

View in Storybook · core-xdsappshell--auto-height

Controlled Collapse

Screenshot:

Controlled Collapse

View in Storybook · core-xdsappshell--controlled-collapse

Content Only

Screenshot:

Content Only

View in Storybook · core-xdsappshell--content-only

With Banner

Screenshot:

With Banner

View in Storybook · core-xdsappshell--with-banner

With Mobile Nav

Screenshot:

With Mobile Nav

View in Storybook · core-xdsappshell--with-mobile-nav

XDSIcon

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdsicon--default

Primary

Screenshot:

Primary

View in Storybook · core-xdsicon--primary

Secondary

Screenshot:

Secondary

View in Storybook · core-xdsicon--secondary

Accent

Screenshot:

Accent

View in Storybook · core-xdsicon--accent

Positive

Screenshot:

Positive

View in Storybook · core-xdsicon--positive

Negative

Screenshot:

Negative

View in Storybook · core-xdsicon--negative

Warning

Screenshot:

Warning

View in Storybook · core-xdsicon--warning

Extra Small

Screenshot:

Extra Small

View in Storybook · core-xdsicon--extra-small

Small

Screenshot:

Small

View in Storybook · core-xdsicon--small

Medium

Screenshot:

Medium

View in Storybook · core-xdsicon--medium

Large

Screenshot:

Large

View in Storybook · core-xdsicon--large

Solid Icon

Screenshot:

Solid Icon

View in Storybook · core-xdsicon--solid-icon

All Colors

Screenshot:

All Colors

View in Storybook · core-xdsicon--all-colors

All Sizes

Screenshot:

All Sizes

View in Storybook · core-xdsicon--all-sizes

Outline Vs Solid

Screenshot:

Outline Vs Solid

View in Storybook · core-xdsicon--outline-vs-solid

Inherit Color

Screenshot:

Inherit Color

View in Storybook · core-xdsicon--inherit-color

XDSMobileNav

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · navigation-xdsmobilenav--default

With SideNav Children

Screenshot:

With SideNav Children

View in Storybook · navigation-xdsmobilenav--with-side-nav-children

Responsive Pattern

Screenshot:

Responsive Pattern

View in Storybook · navigation-xdsmobilenav--responsive-pattern

End Side

Screenshot:

End Side

View in Storybook · navigation-xdsmobilenav--end-side

Custom Width

Screenshot:

Custom Width

View in Storybook · navigation-xdsmobilenav--custom-width

Without Title

Screenshot:

Without Title

View in Storybook · navigation-xdsmobilenav--without-title


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

@cixzhang

Copy link
Copy Markdown
Contributor Author

We should have a story that demonstrates this with the app shell and a full pattern involving the other nav on desktop.

@cixzhang
cixzhang force-pushed the navi/feat/mobile-nav branch from 4c45ef5 to b4f3b25 Compare February 25, 2026 09:30

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lightweight Night Watch review — all guidelines checks pass. ✅

Checked:

  • ✅ Design tokens — colors via colorVars, spacing via spacingVars, radii via radiusVars
  • ✅ Accessibility — role="dialog", aria-modal, aria-label, focus trap via useFocusTrap, Escape key, body scroll lock
  • ✅ Hover guards — no :hover styles (drawer component, no hover interactions needed)
  • ✅ Primitive reuse — XDSButton, XDSIcon, XDSHeading (no raw <button> or <h*>)
  • ✅ Composition — 357 lines, displayName set, theming via module augmentation
  • ✅ Slot pattern — mobileNav prop on AppShell follows the passthrough slot convention (consumer owns the element and its state)

No guidelines issues found.


Crafted with care by Navi — Night Watch Reviewer

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This uses position: fixed + z-index: 1000 for the overlay — same pattern that caused the cascade of z-index fixes in #377/#378/#379 for the mega menu.

The drawer should use the top layer instead. Two options:

  1. <dialog> + showModal() — XDSDialog already does this. Gets you ::backdrop, top layer, and Escape handling for free.
  2. Popover API via useXDSLayer — what tooltips/popovers already use.

Option 1 is probably the better fit for a modal drawer. See issue #411 for the full context.

The z-index: 1000 and manual scroll lock / focus trap / backdrop click handling would all go away — the platform gives you all of that.

cixzhang added a commit that referenced this pull request Mar 3, 2026
Addresses review feedback on #341:

1. **Migrate to top layer**: Replace position:fixed + z-index:1000 with
   native <dialog> + showModal(). The browser's top layer eliminates
   z-index stacking issues entirely. This also removes manual:
   - Body scroll lock (showModal handles it)
   - Focus trapping (showModal handles it)
   - Backdrop element (::backdrop pseudo-element)
   - useFocusTrap dependency

2. **Add Full App Shell Pattern story**: New story in MobileNav.stories
   showing the complete responsive pattern — TopNav + SideNav on desktop,
   hamburger + MobileNav drawer on mobile, all within XDSAppShell.

Follows the same pattern as XDSDialog. See issue #411 for context.

Test plan:
- 1044 tests pass (13 MobileNav + full suite)
- Build passes (core + both themes)
- Lint clean (0 errors)
@cixzhang

cixzhang commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both items:

1. <dialog> + showModal() migration — Replaced the position: fixed + z-index: 1000 + manual backdrop/focus-trap/scroll-lock with a native <dialog> element using showModal(). Same pattern as XDSDialog. The browser's top layer handles everything that was manual before:

  • No z-index (top layer is immune to stacking contexts)
  • ::backdrop pseudo-element replaces the manual backdrop div
  • Native focus trapping (removed useFocusTrap dependency)
  • Native body scroll lock
  • Escape via cancel event

2. Full App Shell Pattern story — Added a new story in MobileNav.stories.tsx showing the complete responsive integration: TopNav + SideNav on desktop, hamburger → MobileNav drawer on mobile, all composed within XDSAppShell. Layout: fullscreen.

All 1044 tests pass, build clean, lint clean.

cixzhang and others added 6 commits March 3, 2026 15:00
… order

- Fix RTL bug: use conditional StyleX transforms with :is([dir="rtl"] *)
  selector to flip translateX direction for RTL layouts (M2)
- Fix SSR hydration mismatch: initialize useMediaQuery state to false
  instead of reading window.matchMedia synchronously (M3)
- Add prefers-reduced-motion support: near-instant transitions (0.01s)
  for both backdrop and drawer when user prefers reduced motion (M4)
- Fix package.json export ordering: move ./MobileNav to correct
  alphabetical position (after ./List, before ./NavIcon)
Adds a story demonstrating the full responsive pattern:
- Desktop (>768px): TopNav with nav items + inline SideNav via AppShell
- Mobile (≤768px): TopNav with hamburger menu button → MobileNav drawer

Shows how MobileNav and SideNav share the same nav sections,
with useMediaQuery driving the layout switch.
Move the app shell integration story from MobileNav.stories to
AppShell.stories where it belongs — this is a layout pattern, not
a MobileNav demo. Reverts MobileNav.stories to its original state.
Add mobileNav, mobileNavTitle, isMobileNavOpen, and onMobileNavOpenChange
props to XDSAppShell. When mobileNav is provided, AppShell renders an
XDSMobileNav drawer internally (with animation, focus trap, close button)
instead of the raw overlay fallback.

The consumer passes nav content once and uses it for both sideNav (desktop)
and mobileNav (mobile). AppShell owns the XDSMobileNav rendering — the
consumer just controls open/close state.

- Component: add mobileNav slot, suppress raw overlay when present
- Story: WithMobileNav uses slot API (no sibling XDSMobileNav)
- Tests: 4 new tests for mobileNav rendering and overlay suppression
- README: document the responsive pattern and new props
Make mobileNav follow the same pattern as topNav, sideNav, and banner:
the consumer passes a fully composed <XDSMobileNav> element with its
own props (isOpen, onClose, title). AppShell just renders it.

Removes isMobileNavOpen, onMobileNavOpenChange, and mobileNavTitle
from AppShell — those belong on XDSMobileNav, not the parent.
Addresses review feedback on #341:

1. **Migrate to top layer**: Replace position:fixed + z-index:1000 with
   native <dialog> + showModal(). The browser's top layer eliminates
   z-index stacking issues entirely. This also removes manual:
   - Body scroll lock (showModal handles it)
   - Focus trapping (showModal handles it)
   - Backdrop element (::backdrop pseudo-element)
   - useFocusTrap dependency

2. **Add Full App Shell Pattern story**: New story in MobileNav.stories
   showing the complete responsive pattern — TopNav + SideNav on desktop,
   hamburger + MobileNav drawer on mobile, all within XDSAppShell.

Follows the same pattern as XDSDialog. See issue #411 for context.

Test plan:
- 1044 tests pass (13 MobileNav + full suite)
- Build passes (core + both themes)
- Lint clean (0 errors)
@cixzhang
cixzhang force-pushed the navi/feat/mobile-nav branch from 7451643 to c228a00 Compare March 3, 2026 15:00

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-Review Summary

5 findings, all fixable. The architecture is solid — passthrough slot pattern, native dialog, RTL, reduced motion, and theming are all done right.

Fixes needed:

  1. Border shorthand → longhand (StyleX convention)
  2. Remove role="document" from drawer div (unnecessary, XDSDialog doesn't use it either)
  3. Remove duplicate FullAppShellPattern story from MobileNav.stories (already in AppShell.stories as WithMobileNav)
  4. Add useMediaQuery tests (every other hook has them)
  5. Replace empty <span /> spacer with marginInlineStart: auto on close button

Will fix all of these now.

},
drawerStart: {
insetInlineStart: 0,
borderInlineEnd: `1px solid ${colorVars['--color-divider']}`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention: Rest of the codebase uses longhand border properties (borderInlineEndWidth, borderInlineEndStyle, borderInlineEndColor) — see XDSLayoutPanel, XDSLayoutHeader. StyleX prefers longhand for deterministic resolution.

Same issue on line 115 (drawerEnd.borderInlineStart) and line 131 (header.borderBlockEnd).

* Nav sections are defined once and shared between both layouts.
* Resize the viewport to see the transition.
*/
export const FullAppShellPattern: Story = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate story: This FullAppShellPattern story is nearly identical to WithMobileNav in AppShell.stories.tsx. Having the same story in two places means maintaining two copies. Since this demonstrates AppShell integration (not MobileNav in isolation), it belongs in AppShell.stories only. Remove from here.

…, clean up stories, add useMediaQuery tests

- Convert border shorthand to longhand properties (StyleX convention)
- Remove unnecessary role="document" from drawer div
- Remove duplicate FullAppShellPattern story (already in AppShell.stories)
- Replace empty <span /> spacer with flex-end alignment for close button
- Add useMediaQuery hook tests (6 tests)
* <DashboardContent />
* </XDSAppShell>
*
* // SideNav only — header provides app identity when there's no TopNav

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having multiple examples elongates the codeblock in storybook, so let's leave it at a simple example demonstrating the 3 nav slots.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — simplified to a single example showing the 3 nav slots (topNav, sideNav, mobileNav) in 14dad2c.

/>

{/* Mobile overlay sideNav */}
{/* Mobile overlay sideNav (legacy — used when mobileNav is not provided) */}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically not legacy since it's a default responsive behavior with side nav. Let's do make sure though that the behaviors are the same, ideally through code sharing with mobile nav if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — it's not legacy, it's the default responsive behavior. Fixed by having AppShell internally render an XDSMobileNav wrapping the sideNav content when no explicit mobileNav slot is provided. Both paths now share the same <dialog>-based implementation.

Removed: manual position: fixed + z-index overlay, backdrop div, manual Escape handler, and all the overlay-related styles. The default mobile nav gets the same top-layer, focus-trap, scroll-lock, and backdrop behavior as the explicit slot. ~100 lines deleted from AppShell.

Also fixed the storybook bug — the dialog had display: 'flex' unconditionally, which overrode the native display: none when closed. The transparent overlay was blocking pointer events on the page even when the drawer wasn't open. Now uses display: { default: 'none', ':where([open])': 'flex' }.

@cixzhang

cixzhang commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Mobile nav drawer appears to be non-functional in the storybook.

…SDoc

- Fix dialog always visible when closed: use display: none/flex
  conditional on [open] attribute instead of unconditional flex.
  The native <dialog> display:none was being overridden, causing
  the transparent overlay to block pointer events even when closed.

- AppShell default mobile overlay now uses XDSMobileNav internally
  instead of manual position:fixed + z-index + backdrop div. Both
  the explicit mobileNav slot and the default responsive behavior
  share the same <dialog>-based implementation.

- Remove manual Escape handler from AppShell (XDSMobileNav handles
  it via native cancel event).

- Simplify AppShell JSDoc to single example showing 3 nav slots.

- Remove unused overlay styles and dynamicStyles from AppShell.

- Update AppShell tests to match new XDSMobileNav-based overlay.
@cixzhang

cixzhang commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 14dad2c. The root cause: the <dialog> element had display: 'flex' set unconditionally via StyleX, which overrode the native display: none when the dialog was closed. The transparent full-viewport overlay was always rendered and blocking pointer events — so clicking the hamburger button (or anything else behind the overlay) didn't work.

Fix: display: { default: 'none', ':where([open])': 'flex' } — respects the native dialog open/closed state while still applying flex layout when open.

@cixzhang
cixzhang added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit a86d79d Mar 4, 2026
14 checks passed
@cixzhang
cixzhang deleted the navi/feat/mobile-nav branch March 13, 2026 10:50
cixzhang added a commit that referenced this pull request Apr 26, 2026
…u icon (#341)

* fix(MobileNav): RTL transforms, SSR hydration, reduced motion, export order

- Fix RTL bug: use conditional StyleX transforms with :is([dir="rtl"] *)
  selector to flip translateX direction for RTL layouts (M2)
- Fix SSR hydration mismatch: initialize useMediaQuery state to false
  instead of reading window.matchMedia synchronously (M3)
- Add prefers-reduced-motion support: near-instant transitions (0.01s)
  for both backdrop and drawer when user prefers reduced motion (M4)
- Fix package.json export ordering: move ./MobileNav to correct
  alphabetical position (after ./List, before ./NavIcon)

* feat(MobileNav): add App Shell Integration story

Adds a story demonstrating the full responsive pattern:
- Desktop (>768px): TopNav with nav items + inline SideNav via AppShell
- Mobile (≤768px): TopNav with hamburger menu button → MobileNav drawer

Shows how MobileNav and SideNav share the same nav sections,
with useMediaQuery driving the layout switch.

* feat(AppShell): add WithMobileNav story, revert MobileNav stories

Move the app shell integration story from MobileNav.stories to
AppShell.stories where it belongs — this is a layout pattern, not
a MobileNav demo. Reverts MobileNav.stories to its original state.

* feat(AppShell): add mobileNav slot for responsive navigation

Add mobileNav, mobileNavTitle, isMobileNavOpen, and onMobileNavOpenChange
props to XDSAppShell. When mobileNav is provided, AppShell renders an
XDSMobileNav drawer internally (with animation, focus trap, close button)
instead of the raw overlay fallback.

The consumer passes nav content once and uses it for both sideNav (desktop)
and mobileNav (mobile). AppShell owns the XDSMobileNav rendering — the
consumer just controls open/close state.

- Component: add mobileNav slot, suppress raw overlay when present
- Story: WithMobileNav uses slot API (no sibling XDSMobileNav)
- Tests: 4 new tests for mobileNav rendering and overlay suppression
- README: document the responsive pattern and new props

* refactor(AppShell): mobileNav as passthrough slot, not wrapper

Make mobileNav follow the same pattern as topNav, sideNav, and banner:
the consumer passes a fully composed <XDSMobileNav> element with its
own props (isOpen, onClose, title). AppShell just renders it.

Removes isMobileNavOpen, onMobileNavOpenChange, and mobileNavTitle
from AppShell — those belong on XDSMobileNav, not the parent.

* refactor(MobileNav): use native <dialog> + showModal() for top layer

Addresses review feedback on #341:

1. **Migrate to top layer**: Replace position:fixed + z-index:1000 with
   native <dialog> + showModal(). The browser's top layer eliminates
   z-index stacking issues entirely. This also removes manual:
   - Body scroll lock (showModal handles it)
   - Focus trapping (showModal handles it)
   - Backdrop element (::backdrop pseudo-element)
   - useFocusTrap dependency

2. **Add Full App Shell Pattern story**: New story in MobileNav.stories
   showing the complete responsive pattern — TopNav + SideNav on desktop,
   hamburger + MobileNav drawer on mobile, all within XDSAppShell.

Follows the same pattern as XDSDialog. See issue #411 for context.

Test plan:
- 1044 tests pass (13 MobileNav + full suite)
- Build passes (core + both themes)
- Lint clean (0 errors)

* fix(MobileNav): review fixes — longhand borders, remove role=document, clean up stories, add useMediaQuery tests

- Convert border shorthand to longhand properties (StyleX convention)
- Remove unnecessary role="document" from drawer div
- Remove duplicate FullAppShellPattern story (already in AppShell.stories)
- Replace empty <span /> spacer with flex-end alignment for close button
- Add useMediaQuery hook tests (6 tests)

* fix(MobileNav): dialog display fix, AppShell code sharing, simplify JSDoc

- Fix dialog always visible when closed: use display: none/flex
  conditional on [open] attribute instead of unconditional flex.
  The native <dialog> display:none was being overridden, causing
  the transparent overlay to block pointer events even when closed.

- AppShell default mobile overlay now uses XDSMobileNav internally
  instead of manual position:fixed + z-index + backdrop div. Both
  the explicit mobileNav slot and the default responsive behavior
  share the same <dialog>-based implementation.

- Remove manual Escape handler from AppShell (XDSMobileNav handles
  it via native cancel event).

- Simplify AppShell JSDoc to single example showing 3 nav slots.

- Remove unused overlay styles and dynamicStyles from AppShell.

- Update AppShell tests to match new XDSMobileNav-based overlay.

---------

Co-authored-by: Navi <[email protected]>
Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
…u icon (#341)

* fix(MobileNav): RTL transforms, SSR hydration, reduced motion, export order

- Fix RTL bug: use conditional StyleX transforms with :is([dir="rtl"] *)
  selector to flip translateX direction for RTL layouts (M2)
- Fix SSR hydration mismatch: initialize useMediaQuery state to false
  instead of reading window.matchMedia synchronously (M3)
- Add prefers-reduced-motion support: near-instant transitions (0.01s)
  for both backdrop and drawer when user prefers reduced motion (M4)
- Fix package.json export ordering: move ./MobileNav to correct
  alphabetical position (after ./List, before ./NavIcon)

* feat(MobileNav): add App Shell Integration story

Adds a story demonstrating the full responsive pattern:
- Desktop (>768px): TopNav with nav items + inline SideNav via AppShell
- Mobile (≤768px): TopNav with hamburger menu button → MobileNav drawer

Shows how MobileNav and SideNav share the same nav sections,
with useMediaQuery driving the layout switch.

* feat(AppShell): add WithMobileNav story, revert MobileNav stories

Move the app shell integration story from MobileNav.stories to
AppShell.stories where it belongs — this is a layout pattern, not
a MobileNav demo. Reverts MobileNav.stories to its original state.

* feat(AppShell): add mobileNav slot for responsive navigation

Add mobileNav, mobileNavTitle, isMobileNavOpen, and onMobileNavOpenChange
props to XDSAppShell. When mobileNav is provided, AppShell renders an
XDSMobileNav drawer internally (with animation, focus trap, close button)
instead of the raw overlay fallback.

The consumer passes nav content once and uses it for both sideNav (desktop)
and mobileNav (mobile). AppShell owns the XDSMobileNav rendering — the
consumer just controls open/close state.

- Component: add mobileNav slot, suppress raw overlay when present
- Story: WithMobileNav uses slot API (no sibling XDSMobileNav)
- Tests: 4 new tests for mobileNav rendering and overlay suppression
- README: document the responsive pattern and new props

* refactor(AppShell): mobileNav as passthrough slot, not wrapper

Make mobileNav follow the same pattern as topNav, sideNav, and banner:
the consumer passes a fully composed <XDSMobileNav> element with its
own props (isOpen, onClose, title). AppShell just renders it.

Removes isMobileNavOpen, onMobileNavOpenChange, and mobileNavTitle
from AppShell — those belong on XDSMobileNav, not the parent.

* refactor(MobileNav): use native <dialog> + showModal() for top layer

Addresses review feedback on #341:

1. **Migrate to top layer**: Replace position:fixed + z-index:1000 with
   native <dialog> + showModal(). The browser's top layer eliminates
   z-index stacking issues entirely. This also removes manual:
   - Body scroll lock (showModal handles it)
   - Focus trapping (showModal handles it)
   - Backdrop element (::backdrop pseudo-element)
   - useFocusTrap dependency

2. **Add Full App Shell Pattern story**: New story in MobileNav.stories
   showing the complete responsive pattern — TopNav + SideNav on desktop,
   hamburger + MobileNav drawer on mobile, all within XDSAppShell.

Follows the same pattern as XDSDialog. See issue #411 for context.

Test plan:
- 1044 tests pass (13 MobileNav + full suite)
- Build passes (core + both themes)
- Lint clean (0 errors)

* fix(MobileNav): review fixes — longhand borders, remove role=document, clean up stories, add useMediaQuery tests

- Convert border shorthand to longhand properties (StyleX convention)
- Remove unnecessary role="document" from drawer div
- Remove duplicate FullAppShellPattern story (already in AppShell.stories)
- Replace empty <span /> spacer with flex-end alignment for close button
- Add useMediaQuery hook tests (6 tests)

* fix(MobileNav): dialog display fix, AppShell code sharing, simplify JSDoc

- Fix dialog always visible when closed: use display: none/flex
  conditional on [open] attribute instead of unconditional flex.
  The native <dialog> display:none was being overridden, causing
  the transparent overlay to block pointer events even when closed.

- AppShell default mobile overlay now uses XDSMobileNav internally
  instead of manual position:fixed + z-index + backdrop div. Both
  the explicit mobileNav slot and the default responsive behavior
  share the same <dialog>-based implementation.

- Remove manual Escape handler from AppShell (XDSMobileNav handles
  it via native cancel event).

- Simplify AppShell JSDoc to single example showing 3 nav slots.

- Remove unused overlay styles and dynamicStyles from AppShell.

- Update AppShell tests to match new XDSMobileNav-based overlay.

---------

Co-authored-by: Navi <[email protected]>
Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
…u icon (#341)

* fix(MobileNav): RTL transforms, SSR hydration, reduced motion, export order

- Fix RTL bug: use conditional StyleX transforms with :is([dir="rtl"] *)
  selector to flip translateX direction for RTL layouts (M2)
- Fix SSR hydration mismatch: initialize useMediaQuery state to false
  instead of reading window.matchMedia synchronously (M3)
- Add prefers-reduced-motion support: near-instant transitions (0.01s)
  for both backdrop and drawer when user prefers reduced motion (M4)
- Fix package.json export ordering: move ./MobileNav to correct
  alphabetical position (after ./List, before ./NavIcon)

* feat(MobileNav): add App Shell Integration story

Adds a story demonstrating the full responsive pattern:
- Desktop (>768px): TopNav with nav items + inline SideNav via AppShell
- Mobile (≤768px): TopNav with hamburger menu button → MobileNav drawer

Shows how MobileNav and SideNav share the same nav sections,
with useMediaQuery driving the layout switch.

* feat(AppShell): add WithMobileNav story, revert MobileNav stories

Move the app shell integration story from MobileNav.stories to
AppShell.stories where it belongs — this is a layout pattern, not
a MobileNav demo. Reverts MobileNav.stories to its original state.

* feat(AppShell): add mobileNav slot for responsive navigation

Add mobileNav, mobileNavTitle, isMobileNavOpen, and onMobileNavOpenChange
props to XDSAppShell. When mobileNav is provided, AppShell renders an
XDSMobileNav drawer internally (with animation, focus trap, close button)
instead of the raw overlay fallback.

The consumer passes nav content once and uses it for both sideNav (desktop)
and mobileNav (mobile). AppShell owns the XDSMobileNav rendering — the
consumer just controls open/close state.

- Component: add mobileNav slot, suppress raw overlay when present
- Story: WithMobileNav uses slot API (no sibling XDSMobileNav)
- Tests: 4 new tests for mobileNav rendering and overlay suppression
- README: document the responsive pattern and new props

* refactor(AppShell): mobileNav as passthrough slot, not wrapper

Make mobileNav follow the same pattern as topNav, sideNav, and banner:
the consumer passes a fully composed <XDSMobileNav> element with its
own props (isOpen, onClose, title). AppShell just renders it.

Removes isMobileNavOpen, onMobileNavOpenChange, and mobileNavTitle
from AppShell — those belong on XDSMobileNav, not the parent.

* refactor(MobileNav): use native <dialog> + showModal() for top layer

Addresses review feedback on #341:

1. **Migrate to top layer**: Replace position:fixed + z-index:1000 with
   native <dialog> + showModal(). The browser's top layer eliminates
   z-index stacking issues entirely. This also removes manual:
   - Body scroll lock (showModal handles it)
   - Focus trapping (showModal handles it)
   - Backdrop element (::backdrop pseudo-element)
   - useFocusTrap dependency

2. **Add Full App Shell Pattern story**: New story in MobileNav.stories
   showing the complete responsive pattern — TopNav + SideNav on desktop,
   hamburger + MobileNav drawer on mobile, all within XDSAppShell.

Follows the same pattern as XDSDialog. See issue #411 for context.

Test plan:
- 1044 tests pass (13 MobileNav + full suite)
- Build passes (core + both themes)
- Lint clean (0 errors)

* fix(MobileNav): review fixes — longhand borders, remove role=document, clean up stories, add useMediaQuery tests

- Convert border shorthand to longhand properties (StyleX convention)
- Remove unnecessary role="document" from drawer div
- Remove duplicate FullAppShellPattern story (already in AppShell.stories)
- Replace empty <span /> spacer with flex-end alignment for close button
- Add useMediaQuery hook tests (6 tests)

* fix(MobileNav): dialog display fix, AppShell code sharing, simplify JSDoc

- Fix dialog always visible when closed: use display: none/flex
  conditional on [open] attribute instead of unconditional flex.
  The native <dialog> display:none was being overridden, causing
  the transparent overlay to block pointer events even when closed.

- AppShell default mobile overlay now uses XDSMobileNav internally
  instead of manual position:fixed + z-index + backdrop div. Both
  the explicit mobileNav slot and the default responsive behavior
  share the same <dialog>-based implementation.

- Remove manual Escape handler from AppShell (XDSMobileNav handles
  it via native cancel event).

- Simplify AppShell JSDoc to single example showing 3 nav slots.

- Remove unused overlay styles and dynamicStyles from AppShell.

- Update AppShell tests to match new XDSMobileNav-based overlay.

---------
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
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.

discussion: responsive navigation patterns for XDSAppShell

1 participant