Skip to content

bugfix(Dialog): Fixing issue where page shifts when dialog is open #6266

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

Merged
merged 5 commits into from
Jul 2, 2025

Conversation

jonrohan
Copy link
Member

@jonrohan jonrohan commented Jul 1, 2025

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

This PR changes how we turn on disable scrolling when the dialog is open. The strategy was taken from what we do in PVC. https://github.com/primer/view_components/blob/2677324d35cac1ce5ebf9aede851fa4267f7c6e2/app/components/primer/dialog_helper.ts#L81

We essentially set a variable on the body element that equals the width of the scrollbar. And turns padding on when that scrollbar is hidden.

I also used this as an opportunity to cleanup the old inline styles we were doing for hidding, and migrated the test to vitest in the process for the toHaveStyle assertion.

Changelog

New

Changed

Dialog adds padding to page when scrollbar is hidden.

Removed

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

@github-actions github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jul 1, 2025
Copy link
Contributor

github-actions bot commented Jul 1, 2025

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

github-actions bot commented Jul 1, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.42 KB (-0.06% 🔽)
packages/react/dist/browser.umd.js 92.6 KB (+0.16% 🔺)

Copy link

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: 8d35de2

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 requested a deployment to storybook-preview-6266 July 1, 2025 22:18 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6266 July 1, 2025 22:32 Inactive
@jonrohan jonrohan changed the title Fixing issue where page shifts when dialog is open bugfix(Dialog): Fixing issue where page shifts when dialog is open Jul 2, 2025
@github-actions github-actions bot requested a deployment to storybook-preview-6266 July 2, 2025 17:59 Abandoned
return () => {
document.body.style.overflow = bodyOverflowStyle
}
document.body.style.setProperty('--dialog-scrollgutter', `${window.innerWidth - document.body.clientWidth}px`)
Copy link
Member Author

@jonrohan jonrohan Jul 2, 2025

Choose a reason for hiding this comment

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

I cleared up this overflow style setting since we can include it in the class. The property I'm setting here is identical to what we have in PVC https://github.com/primer/view_components/blob/2677324d35cac1ce5ebf9aede851fa4267f7c6e2/app/components/primer/dialog_helper.ts#L81

But I want to know if useEffect is the correct callback to have this in?

Copy link
Member

Choose a reason for hiding this comment

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

@jonrohan I think that's the right place to have it 👍

@@ -339,7 +327,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
data-width={width}
data-height={height}
sx={sx}
className={clsx(className, classes.Dialog)}
className={clsx(className, classes.Dialog, classes.DisableScroll)}
Copy link
Member Author

Choose a reason for hiding this comment

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

Opted to add a separate class here in case we wanted to make this a prop in the future, which is what we do in PVC

inherits: false;
syntax: '<length>';
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of this implementation was taken from what we did in PVC primer/view_components#2542

return () => {
document.body.style.overflow = bodyOverflowStyle
}
document.body.style.setProperty('--dialog-scrollgutter', `${window.innerWidth - document.body.clientWidth}px`)
Copy link
Member

Choose a reason for hiding this comment

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

@jonrohan I think that's the right place to have it 👍

@jonrohan jonrohan added this pull request to the merge queue Jul 2, 2025
Merged via the queue into main with commit ac5a9c1 Jul 2, 2025
48 of 50 checks passed
@jonrohan jonrohan deleted the dialog_scroll_branch_fix branch July 2, 2025 18:45
@primer primer bot mentioned this pull request Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants