Skip to content

SelectPanel: Lock body scroll when modal variant is open#7757

Open
liuliu-dev wants to merge 3 commits intomainfrom
liuliu/selectpanel-lock-scroll-modal-variant
Open

SelectPanel: Lock body scroll when modal variant is open#7757
liuliu-dev wants to merge 3 commits intomainfrom
liuliu/selectpanel-lock-scroll-modal-variant

Conversation

@liuliu-dev
Copy link
Copy Markdown
Contributor

Closes https://github.com/github/primer/issues/6548

Changelog

SelectPanel with variant="modal" did not lock the body's scrollbar, allowing users to scroll behind both the dialog and backdrop. Now body scroll is now locked when variant="modal" is open.

Before After
Screenshot 2026-04-14 at 2 45 28 PM Screenshot 2026-04-14 at 2 45 38 PM

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: f5b44c8

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

@liuliu-dev liuliu-dev added the Canary Release Apply this label when you want CI to create a canary release of the current PR label Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Uh oh! @liuliu-dev, at least one image you shared is missing helpful alt text. Check your pull request body to fix the following violations:

  • Images should have meaningful alternative text (alt text) at line 13
  • Images should have meaningful alternative text (alt text) at line 13
  • Images should have meaningful alternative text (alt text) at line 13
  • Images should have meaningful alternative text (alt text) at line 13

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@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 Apr 14, 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.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

@primer-integration
Copy link
Copy Markdown

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/18621

@primer-integration
Copy link
Copy Markdown

Integration test results from github/github-ui:

Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

@liuliu-dev liuliu-dev marked this pull request as ready for review April 14, 2026 23:08
@liuliu-dev liuliu-dev requested a review from a team as a code owner April 14, 2026 23:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes SelectPanel’s modal UX by preventing page scrolling behind the modal/backdrop, aligning modal behavior with typical overlay expectations.

Changes:

  • Lock <body> scrolling when SelectPanel is open in variant="modal" (in addition to the existing narrow-screen fullscreen behavior).
  • Add unit tests verifying body scroll is locked on open and restored on close for the modal variant.
  • Update the modal backdrop styling to use position: fixed so it covers the viewport.
Show a summary per file
File Description
packages/react/src/SelectPanel/SelectPanel.tsx Extends body scroll locking condition to include variant="modal" and updates effect deps.
packages/react/src/SelectPanel/SelectPanel.test.tsx Adds tests asserting body overflow is hidden on modal open and restored on close.
packages/react/src/SelectPanel/SelectPanel.module.css Changes .Backdrop positioning from absolute to fixed for full-viewport coverage.
.changeset/gold-humans-tap.md Adds a patch changeset entry for the behavior change.

Copilot's findings

Comments suppressed due to low confidence (1)

packages/react/src/SelectPanel/SelectPanel.tsx:374

  • The body scroll lock logic bails out when document.body.style.overflow is already 'hidden', but that breaks the case where two SelectPanel modals are open at the same time: the second instance will skip registering a cleanup, and when the first unmounts/closes it will restore body scrolling even though the second is still open. Consider switching to a ref-counted approach (like Dialog’s data-dialog-scroll-disabled pattern) so scroll is only restored when the last SelectPanel requiring the lock closes.
    if (open && (variant === 'modal' || (isNarrowScreenSize && usingFullScreenOnNarrow))) {
      const bodyOverflowStyle = document.body.style.overflow || ''
      // If the body is already set to overflow: hidden, it likely means
      // that there is already a modal open. In that case, we should bail
      // so we don't re-enable scroll after the second dialog is closed.
      if (bodyOverflowStyle === 'hidden') {
        return
      }
  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canary Release Apply this label when you want CI to create a canary release of the current PR 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