Skip to content

fix(PageLayout): hide sidebar resize control when resizing is unavailable - #8787

Draft
adierkens wants to merge 4 commits into
mainfrom
adierkens-pagelayout-resize-availability
Draft

adierkens wants to merge 4 commits into
mainfrom
adierkens-pagelayout-resize-availability

Conversation

@adierkens

Copy link
Copy Markdown
Contributor

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

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4dfd066

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

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

@github-actions
github-actions Bot temporarily deployed to storybook-preview-8787 November 17, 2026 17:51 Inactive
@github-actions github-actions Bot added the integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh label Nov 17, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

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

@github-actions
github-actions Bot temporarily deployed to storybook-preview-8787 November 17, 2026 19:32 Inactive
@github-actions github-actions Bot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh labels Nov 17, 2026
@primer-integration

primer-integration Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Waiting  Changes   Waiting
Passed  CI   Passed
Running  VRT   Running
Waiting  Projects   Waiting

@github-actions github-actions Bot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels Nov 17, 2026
@adierkens
adierkens requested a balanced review from Copilot November 17, 2026 21:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

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.
packages/​react/​src/​PageLayout/​PageLayout.test.tsx Cover resize availability and keyboard boundary behavior.
packages/​react/​src/​PageLayout/​PageLayout.features.stories.tsx Expose minimum, default, and maximum width controls.
.changeset/​pagelayout-sidebar-resize-availability.md Document the patch release’s sidebar behavior change.
.agents/​skills/​storybook/​SKILL.md Require reproducible story examples for prop-driven UI changes.

Review effort: Balanced

}
>
{resizable ? (
{resizable && maxPaneWidth > minPaneWidth ? (
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

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

@Ultroncn Ultroncn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for this PR — hiding the handle when it has no range to resize into is a nice touch. One thing I noticed while reading through it:

Comment on lines 218 to +227
React.useEffect(() => {
return () => {
if (rafIdRef.current !== null) {
cancelAnimationFrame(rafIdRef.current)
rafIdRef.current = null
pendingClientXRef.current = null
}
endDragging()
}
}, [])
}, [endDragging])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Keep resize handle mounted when pane bounds change

packages/​react/​src/​PageLayout/​PageLayout.tsx:253

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.

Review effort: Balanced

}
>
{resizable ? (
{resizable && maxPaneWidth > minPaneWidth ? (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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 () => {
  const layout = (width: {min: '100px' | '250px', default: '150px' | '260px', max: '200px' | '300px'}) => (
    <PageLayout>
      <PageLayout.Content>Content</PageLayout.Content>
      <PageLayout.Sidebar resizable width={width}>
        Sidebar
      </PageLayout.Sidebar>
    </PageLayout>
  )
  const {rerender} = render(layout({min: '100px', default: '150px', max: '200px'}))
  const handle = page.getByRole('slider')
  await expect.element(handle).toBeVisible()
  const handleElement = handle.element()
  act(() => handleElement.focus())
  rerender(layout({min: '250px', default: '260px', max: '300px'}))
  await expect.element(page.getByRole('slider')).toBeVisible()
  expect(handle.element()).toBe(handleElement)
  expect(document.activeElement).toBe(handleElement)
})

This branch was successfully deployed

2 active deployments
storybook-preview-8787 — 4dfd066d Deployed Nov 19, 2026 by github-actions[bot]
github-pages — 4dfd066d Deployed Nov 19, 2026 by adierkens via deploy-preview #34426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants