Skip to content

Prevents body scroll when Dialog is open - #3547

Merged
mperrotti merged 6 commits into
mainfrom
mp/dialog-scroll-fix
Jul 26, 2023
Merged

Prevents body scroll when Dialog is open#3547
mperrotti merged 6 commits into
mainfrom
mp/dialog-scroll-fix

Conversation

@mperrotti

@mperrottimperrotti commented Jul 21, 2023

Copy link
Copy Markdown
Contributor

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

Closeshttps://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 joshblackJuly 21, 2023 18:47
@changeset-bot

changeset-botBot commented Jul 21, 2023

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactPatch

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

@github-actions

github-actionsBot commented Jul 21, 2023

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js102.45 KB (+0.04% 🔺)
dist/browser.umd.js103.05 KB (+0.05% 🔺)

@github-actions
github-actionsBot 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-actionsBot 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-actionsBot temporarily deployed to storybook-preview-3547 July 21, 2023 19:06 Inactive
Comment threadsrc/Dialog/Dialog.tsx Outdated
document.body.style.overflow = 'hidden'

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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-actionsBot 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-actionsBot temporarily deployed to storybook-preview-3547 July 25, 2023 17:26 Inactive
@mperrotti
mperrotti enabled auto-merge July 26, 2023 17:46
@github-actions
github-actionsBottemporarily deployed to storybook-preview-3547 July 26, 2023 17:52 Inactive
@mperrotti
mperrotti added this pull request to the merge queueJul 26, 2023
Merged via the queue into main with commit 7ef802eJul 26, 2023
@mperrotti
mperrotti deleted the mp/dialog-scroll-fix branch July 26, 2023 18:06
This was referenced Jul 26, 2023
@cyeetcyeet mentioned this pull request Jan 3, 2025
13 tasks
Sign up for freeto 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

@mperrotti@siddharthkp@joshblack