Skip to content

feat(SideNav): resizable sidebar with drag handle - #658

Merged
cixzhang merged 3 commits into
mainfrom
navi/feat/resizable-sidenav
Mar 18, 2026
Merged

cixzhang merged 3 commits into
mainfrom
navi/feat/resizable-sidenav

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

feat(SideNav): Resizable Sidebar with Drag Handle

Adds a resizable prop to XDSSideNav using the boolean-or-config pattern (same as collapsible).

API

// Simple — enable with defaults (260px initial width)
<XDSSideNav resizable>

// Configured
<XDSSideNav resizable={{ defaultWidth: 300, onWidthChange: (w) => save(w) }}>

// Disabled (default)
<XDSSideNav>

Behavior

  • 6px drag handle at the inline-end edge (position: absolute)
  • Pointer event flow: onPointerDown → document pointermove → document pointerup
  • Width updated via ref during drag (no React state per frame), committed on pointerup
  • Constraints: min 180px, max 480px
  • Body cursor set to col-resize during drag
  • Hidden when sidenav is collapsed
  • role="separator" with aria-orientation="vertical"

Shell Lab

Added "Resizable" toggle to the SideNav config panel.


@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
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 1334 -
Complexity N/A Very High (133) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.5KB 16.7KB 2.6KB

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

Let's use the same API pattern as collapsible with these props as a Boolean flag or option config like "resizable"

@cixzhang

Copy link
Copy Markdown
Contributor Author

Add this option to the shell lab in sandbox so we can test it.

@cixzhang
cixzhang force-pushed the navi/feat/resizable-sidenav branch from 1ce6952 to f67bb33 Compare March 18, 2026 16:03
Replace isResizable/defaultWidth/onWidthChange with a single resizable
prop matching the collapsible pattern:

- resizable={true} — enable with defaults (260px)
- resizable={{ defaultWidth: 300, onWidthChange }} — configured
- resizable={false} or omit — disabled (default)

Added resizable toggle to shell lab for testing.

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

Copy link
Copy Markdown
Contributor Author

Done! Updated in 24e337e — the resizable prop now follows the same boolean-or-config pattern as collapsible:

// Boolean flag
<XDSSideNav resizable>

// Config object
<XDSSideNav resizable={{ defaultWidth: 300, onWidthChange: (w) => save(w) }}>

Also added a "Resizable" toggle to the Shell Lab config panel so you can test it in the sandbox preview.

@cixzhang
cixzhang marked this pull request as ready for review March 18, 2026 16:35
// =========================================================================
// Resize state — pointer-based drag on the inline-end handle
// =========================================================================
const [width, setWidth] = useState(

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.

Can we move all resize feature hooks into a separate useResizeable hook? Then only setup the event listeners if resizeable is enabled.

@cixzhang cixzhang Mar 18, 2026 •

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! Extracted all resize logic into a standalone useResizable hook in useResizable.ts. The hook:

  • Encapsulates all resize state (width, refs, hover state)
  • Only registers pointer event listeners when enabled is true
  • Returns { width, containerRef, showHandle, handleProps, isHandleHovered }
  • XDSSideNav just spreads handleProps onto the drag handle element

All 49 existing tests pass with no changes needed.

Move all resize state, pointer event listeners, and drag logic into
a standalone useResizable hook. The hook only sets up event listeners
when resizable is enabled, and returns handle props + width state.

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang merged commit 16686db into main Mar 18, 2026
11 checks passed
@cixzhang
cixzhang deleted the navi/feat/resizable-sidenav branch March 18, 2026 19:51
@cixzhang cixzhang mentioned this pull request Mar 18, 2026
52 of 55 tasks
cixzhang added a commit that referenced this pull request Apr 26, 2026
* feat(SideNav): resizable sidebar with drag handle

* refactor(SideNav): use boolean-or-config pattern for resizable prop

Replace isResizable/defaultWidth/onWidthChange with a single resizable
prop matching the collapsible pattern:

- resizable={true} — enable with defaults (260px)
- resizable={{ defaultWidth: 300, onWidthChange }} — configured
- resizable={false} or omit — disabled (default)

Added resizable toggle to shell lab for testing.

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

* refactor(SideNav): extract useResizable hook from XDSSideNav

Move all resize state, pointer event listeners, and drag logic into
a standalone useResizable hook. The hook only sets up event listeners
when resizable is enabled, and returns handle props + width state.

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(SideNav): resizable sidebar with drag handle

* refactor(SideNav): use boolean-or-config pattern for resizable prop

Replace isResizable/defaultWidth/onWidthChange with a single resizable
prop matching the collapsible pattern:

- resizable={true} — enable with defaults (260px)
- resizable={{ defaultWidth: 300, onWidthChange }} — configured
- resizable={false} or omit — disabled (default)

Added resizable toggle to shell lab for testing.

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

* refactor(SideNav): extract useResizable hook from XDSSideNav

Move all resize state, pointer event listeners, and drag logic into
a standalone useResizable hook. The hook only sets up event listeners
when resizable is enabled, and returns handle props + width state.

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(SideNav): resizable sidebar with drag handle

* refactor(SideNav): use boolean-or-config pattern for resizable prop

Replace isResizable/defaultWidth/onWidthChange with a single resizable
prop matching the collapsible pattern:

- resizable={true} — enable with defaults (260px)
- resizable={{ defaultWidth: 300, onWidthChange }} — configured
- resizable={false} or omit — disabled (default)

Added resizable toggle to shell lab for testing.


* refactor(SideNav): extract useResizable hook from XDSSideNav

Move all resize state, pointer event listeners, and drag logic into
a standalone useResizable hook. The hook only sets up event listeners
when resizable is enabled, and returns handle props + width state.


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