You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(PageLayout): hide sidebar resize control when resizing is unavailable - #8787
Hide the sidebar resize control when its effective minimum and maximum leave no resize range. Keep the divider and resizing in either available direction.
Changelog
New
N/A
Changed
Hide the resize handle and its focus target for an empty width interval; update availability as constraints change.
Preserve keyboard resizing at either boundary and add regression coverage for both sidebar positions.
Removed
N/A
Rollout strategy
No changes needed in github/github-ui
Needs changes in github/github-ui
Ships with feature flag(s)
Not sure
None
Testing & Reviewing
npx vitest run --project '@primer/react' packages/react/src/PageLayout/PageLayout.test.tsx packages/react/src/PageLayout/usePaneWidth.test.ts — passed (92 tests; 2 existing todos). npm run build and npm run type-check — passed during initial preparation. npx eslint --fix packages/react/src/PageLayout/PageLayout.tsx packages/react/src/PageLayout/PageLayout.test.tsx and npx prettier --check packages/react/src/PageLayout/PageLayout.tsx packages/react/src/PageLayout/PageLayout.test.tsx .changeset/pagelayout-sidebar-resize-availability.md — passed. Full unit/VRT suites and manual focus/assistive-technology review not run.
👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.
👋 Hi, there are new commits since the last successful integration test. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unmounting DragHandle during keyboard resizing leaves active drag styles on the sidebar and content wrapper, making both regions unclickable because cleanup only cancels animation frames.
This PR updates PageLayout.Sidebar to hide its resize control when effective width constraints leave no resize range, while preserving the divider and resizing at either boundary.
Changes:
Render the resize handle only when the effective maximum exceeds the minimum.
Add regression tests for changing constraints, viewport changes, and keyboard resizing at width boundaries.
Add adjustable Storybook width controls, preview guidance, and a patch changeset.
File
Description
packages/react/src/PageLayout/PageLayout.tsx
Hide the resize handle when no width range is available.
👋 Hi, there are new commits since the last successful integration test. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.
The reason will be displayed to describe this comment to others. Learn more.
The new unmount cleanup clears the drag styles but drops the other half of ending a drag: it never calls onDragEnd. Both other drag-end paths pair the two calls (handleLostPointerCapture and handleKeyUp call endDragging() followed by stableOnDragEnd.current()), but the cleanup effect only calls endDragging().
That matters for exactly the case this PR adds: if the constraints collapse while a drag is in progress, the handle unmounts mid-drag (covered by restores interaction when the resize handle disappears before keyup). Both PageLayout call sites pass onDragEnd={() => saveWidth(currentWidthRef.current!)}, and saveWidth is what syncs the React state behind aria-valuenow, fires the consumer's onResizeEnd, or persists to localStorage. With the cleanup as written, the dragged-to width is never saved — aria-valuenow snaps back to the stale value on the next render while the inline --pane-width keeps the dragged width.
Suggested change
React.useEffect(()=>{
return()=>{
if(rafIdRef.current!==null){
cancelAnimationFrame(rafIdRef.current)
rafIdRef.current=null
pendingClientXRef.current=null
}
endDragging()
}
},[])
},[endDragging])
React.useEffect(()=>{
return()=>{
if(rafIdRef.current!==null){
cancelAnimationFrame(rafIdRef.current)
rafIdRef.current=null
pendingClientXRef.current=null
}
if(isDraggingRef.current){
endDragging()
stableOnDragEnd.current()
}
}
},[endDragging])
The isDraggingRef.current guard matters: without it, a plain unmount (no drag in progress) would spuriously fire onDragEnd/saveWidth. It would also be good to extend the restores interaction … test to assert the dragged width is saved — e.g. pass onResizeEnd and expect it to have been called with the dragged width (259 after one ArrowRight from 256px).
👋 Hi, there are new commits since the last successful integration test. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Updating both pane bounds can temporarily unmount the resize handle because the effective bounds update out of sync, causing keyboard focus loss and interrupting active resizing.
minPaneWidth reflects new props immediately, while maxPaneWidth retains the previous value until usePaneWidth updates its state in a transition. Changing min/max from 100/200px to 250/300px at a 1280px viewport therefore temporarily unmounts the handle despite both ranges allowing resizing, losing keyboard focus and ending any active resize. Keep the effective bounds used for availability synchronized, and add a regression asserting that a focused handle stays mounted when both bounds change between nonempty ranges.
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for addressing the drag-cleanup feedback — I verified the unmount cleanup in DragHandle now clears the drag styles and calls onDragEnd (with the isDraggingRef guard), and the regression test covers it, so that part looks resolved.
The second point from the Copilot review still holds, though, in a slightly narrower scope than it was phrased: minPaneWidth is derived during render (usePaneWidth.ts:216), while maxPaneWidth is state that only updates via startTransition in the layout effect (usePaneWidth.ts:407-410, 432-434). When both bounds change at once — e.g. width={{min: '100px', max: '200px'}} to {{min: '250px', max: '300px'}} — the render in between sees the new minPaneWidth (250) with the stale maxPaneWidth (200), so the condition on this line flips to false and the handle briefly unmounts and remounts, losing keyboard focus (and ending any active keyboard resize, though the cleanup now ends it cleanly). The PageLayout.Pane handle is not affected — it is only gated on resizable — this is specific to the SidebarDivider path.
Would it make sense to derive the effective maximum during render (at least the prop-driven part of it) so both bounds change in the same commit, or to flush prop-driven max updates outside the transition? Happy to leave the implementation to you — the key behaviour is that a focused handle stays mounted when both bounds move between ranges that still allow resizing.
Suggested regression test (fails on the current head — the handle remounts and focus is lost — passes once the bounds stay in sync):
it('keeps the resize handle mounted when both bounds change between resizable ranges',async()=>{constlayout=(width: {min: '100px'|'250px',default: '150px'|'260px',max: '200px'|'300px'})=>(<PageLayout><PageLayout.Content>Content</PageLayout.Content><PageLayout.Sidebarresizablewidth={width}>
Sidebar
</PageLayout.Sidebar></PageLayout>)const{rerender}=render(layout({min: '100px',default: '150px',max: '200px'}))consthandle=page.getByRole('slider')awaitexpect.element(handle).toBeVisible()consthandleElement=handle.element()act(()=>handleElement.focus())rerender(layout({min: '250px',default: '260px',max: '300px'}))awaitexpect.element(page.getByRole('slider')).toBeVisible()expect(handle.element()).toBe(handleElement)expect(document.activeElement).toBe(handleElement)})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves github/primer#7303
Hide the sidebar resize control when its effective minimum and maximum leave no resize range. Keep the divider and resizing in either available direction.
Changelog
New
N/A
Changed
Removed
N/A
Rollout strategy
Testing & Reviewing
npx vitest run --project '@primer/react' packages/react/src/PageLayout/PageLayout.test.tsx packages/react/src/PageLayout/usePaneWidth.test.ts— passed (92 tests; 2 existing todos).npm run buildandnpm run type-check— passed during initial preparation.npx eslint --fix packages/react/src/PageLayout/PageLayout.tsx packages/react/src/PageLayout/PageLayout.test.tsxandnpx prettier --check packages/react/src/PageLayout/PageLayout.tsx packages/react/src/PageLayout/PageLayout.test.tsx .changeset/pagelayout-sidebar-resize-availability.md— passed. Full unit/VRT suites and manual focus/assistive-technology review not run.