Repository navigation
feat(MobileNav): add XDSMobileNav drawer, useMediaQuery hook, and menu icon - #341
Conversation
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR New ComponentsMobileNav · View in Storybook
Modified ComponentsAppShell · View in Storybook
Icon · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. XDSIcon - 1 issue(s)
Component PreviewsIncludes interactive hover previews as animated GIFs. XDSAppShellTop Nav With Side NavScreenshot: Interaction Preview: (view video) View in Storybook · XDSIconXDSMobileNavDefaultScreenshot: Interaction Preview: (view video) View in Storybook · With SideNav ChildrenScreenshot: View in Storybook · Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
We should have a story that demonstrates this with the app shell and a full pattern involving the other nav on desktop. |
4c45ef5 to
b4f3b25
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Lightweight Night Watch review — all guidelines checks pass. ✅
Checked:
- ✅ Design tokens — colors via
colorVars, spacing viaspacingVars, radii viaradiusVars - ✅ Accessibility —
role="dialog",aria-modal,aria-label, focus trap viauseFocusTrap, Escape key, body scroll lock - ✅ Hover guards — no
:hoverstyles (drawer component, no hover interactions needed) - ✅ Primitive reuse —
XDSButton,XDSIcon,XDSHeading(no raw<button>or<h*>) - ✅ Composition — 357 lines,
displayNameset, theming via module augmentation - ✅ Slot pattern —
mobileNavprop 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
left a comment
There was a problem hiding this comment.
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:
<dialog>+showModal()—XDSDialogalready does this. Gets you::backdrop, top layer, andEscapehandling for free.- 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.
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)
|
Addressed both items: 1.
2. Full App Shell Pattern story — Added a new story in All 1044 tests pass, build clean, lint clean. |
… 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)
7451643 to
c228a00
Compare
cixzhang
left a comment
There was a problem hiding this comment.
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:
- Border shorthand → longhand (StyleX convention)
- Remove
role="document"from drawer div (unnecessary, XDSDialog doesn't use it either) - Remove duplicate
FullAppShellPatternstory from MobileNav.stories (already in AppShell.stories asWithMobileNav) - Add
useMediaQuerytests (every other hook has them) - Replace empty
<span />spacer withmarginInlineStart: autoon close button
Will fix all of these now.
| }, | ||
| drawerStart: { | ||
| insetInlineStart: 0, | ||
| borderInlineEnd: `1px solid ${colorVars['--color-divider']}`, |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Having multiple examples elongates the codeblock in storybook, so let's leave it at a simple example demonstrating the 3 nav slots.
There was a problem hiding this comment.
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) */} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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' }.
|
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.
|
Fixed in 14dad2c. The root cause: the Fix: |
…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]>
…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]>
…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. ---------
Summary
Adds
XDSMobileNav— a slide-out drawer overlay for mobile navigation. The mobile counterpart toXDSSideNav, accepting the same children (XDSSideNavSection,XDSSideNavItem, or any ReactNode).Also ships:
useMediaQueryhook — SSR-safe, used for responsive patternsmenuicon — hamburger icon added to the semantic icon set (default + neutral themes)API
Vibe Test Results
Ran a focused vibe test (8 prompts, XDS vs baseline/Tailwind):
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
packages/core/src/MobileNav/XDSMobileNav.tsxpackages/core/src/MobileNav/XDSMobileNav.test.tsxpackages/core/src/MobileNav/README.mdpackages/core/src/hooks/useMediaQuery.tsapps/storybook/stories/MobileNav.stories.tsxAccessibility
role="dialog"+aria-modal="true"useFocusTraphookprefers-reduced-motionrespected (near-instant transitions)[dir="rtl"]flips slide direction)Test Plan
Closes #329
Crafted with care by Navi