Skip to content

feat(SideNav): add popover for collapsed items with children - #655

Closed
cixzhang wants to merge 1 commit into
mainfrom
navi/feat/collapsed-subnav-popover
Closed

cixzhang wants to merge 1 commit into
mainfrom
navi/feat/collapsed-subnav-popover

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

What

When the SideNav is collapsed to an icon-only toolbar (52px), items that have sub-items (children) now show a popover when clicked. This lets users access nested navigation without expanding the sidebar.

How

Collapsed item with children → Popover trigger

  • The parent icon-only button becomes a popover trigger (aria-haspopup="dialog")
  • Clicking it opens a popover positioned to the right (placement: 'end')
  • The popover contains a header (parent label) and children rendered in expanded form
  • Closes on: click outside, Escape key, or clicking a child item inside

Context provider for expanded rendering

  • Added XDSSideNavCollapseProvider to XDSSideNavCollapseContext.tsx
  • Popover children are wrapped in the provider with isCollapsed: false so nested XDSSideNavItems render their full label text (not icon-only)
  • Renamed .ts → .tsx to support JSX in the provider component

Collapsed items without children

  • Items with icon but no children → icon-only button/link with aria-label
  • Items without icon → hidden (return null)

Files changed

File Change
XDSSideNavCollapseContext.ts → .tsx Added XDSSideNavCollapseProvider, converted to JSX
XDSSideNavItem.tsx Added collapsed mode rendering with popover
XDSSideNav.test.tsx Added 9 new tests for collapsed behavior
index.ts Added XDSSideNavCollapseProvider export

Conventions

  • All :hover styles use @media (hover: hover) guards
  • StyleX for all styling with design tokens
  • Popover uses useXDSPopover with elevation-menu shadow, radius-element border radius, color-surface background

Tests

  • 1517 tests pass (52 in SideNav suite, 9 new)
  • 0 lint errors

Part of #565.


When the SideNav is collapsed to icon-only mode, items with sub-items
(children) now show a popover on click. The popover:

- Appears to the right of the icon-only trigger
- Contains children rendered in expanded form (not collapsed)
- Closes on click outside, escape, or clicking a child item
- Shows the parent label as a header in the popover
- Uses XDS design tokens for surface, border, elevation, and radius

Implementation details:
- Renamed XDSSideNavCollapseContext.ts → .tsx to support JSX
- Added XDSSideNavCollapseProvider for wrapping popover children
  with isCollapsed: false so nested items render expanded
- XDSSideNavItem uses useXDSPopover for positioning/dismiss
- Items without icons return null when collapsed
- All :hover styles use @media (hover: hover) guards
- Added 9 new tests covering collapsed behavior

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

SideNav · View in Storybook · 🆕 XDSSideNavCollapseProvider, XDSSideNavCollapseContext
Metric Before After Delta
Bundle Size (ESM) N/A 1.2KB N/A
Lines of Code N/A 1260 -
Complexity N/A Very High (122) -

Bundle Size Summary

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

Copy link
Copy Markdown
Contributor Author

Closing — this needs to be re-implemented on top of current main after the shell hardening batch (#657) refactored SideNavItem significantly. Will re-open as a new PR.

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