Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents body scroll when Dialog is open #3547

Merged
merged 6 commits into from
Jul 26, 2023
Merged

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Jul 21, 2023

Sets body to overflow: hidden when a Dialog is mounted.

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

How to test:

Add this line to a story:

<div style={{height: '120vh', width: 1}}>make it scroll</div>

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@mperrotti mperrotti requested review from a team and joshblack July 21, 2023 18:47
@changeset-bot
Copy link

changeset-bot bot commented Jul 21, 2023

🦋 Changeset detected

Latest commit: 85b0390

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

@mperrotti
Copy link
Contributor Author

I'm not sure if this solution is SSR-compatible or not. I tried doing this with CSS using overscroll-behavior, but it didn't work.

@mperrotti
Copy link
Contributor Author

One caveat: this probably won't work on any scrollable elements within the body.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 102.45 KB (+0.04% 🔺)
dist/browser.umd.js 103.05 KB (+0.05% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-3547 July 21, 2023 18:54 Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 21, 2023 18:58 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3547 July 21, 2023 18:59 Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 21, 2023 19:05 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3547 July 21, 2023 19:06 Inactive
document.body.style.overflow = 'hidden'

return () => {
document.body.style.overflow = ''
Copy link
Member

Choose a reason for hiding this comment

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

Not blocking: should we keep a track of what it was set to before and reset to that, just in case it was scroll or clip instead of the default visible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll update it.

@mperrotti mperrotti temporarily deployed to github-pages July 25, 2023 17:10 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3547 July 25, 2023 17:10 Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 25, 2023 17:26 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3547 July 25, 2023 17:26 Inactive
@mperrotti mperrotti enabled auto-merge July 26, 2023 17:46
@mperrotti mperrotti added this pull request to the merge queue Jul 26, 2023
Merged via the queue into main with commit 7ef802e Jul 26, 2023
30 checks passed
@mperrotti mperrotti deleted the mp/dialog-scroll-fix branch July 26, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants