-
Notifications
You must be signed in to change notification settings - Fork 625
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
"@primer/react": patch | ||
--- | ||
Bug fix: Fixing issue where page shifts when Dialog is open |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,19 +288,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP | |
) | ||
|
||
React.useEffect(() => { | ||
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 | ||
} | ||
|
||
document.body.style.overflow = 'hidden' | ||
|
||
return () => { | ||
document.body.style.overflow = bodyOverflowStyle | ||
} | ||
document.body.style.setProperty('--dialog-scrollgutter', `${window.innerWidth - document.body.clientWidth}px`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonrohan I think that's the right place to have it 👍 |
||
}, []) | ||
|
||
const header = (renderHeader ?? DefaultHeader)(defaultedProps) | ||
|
@@ -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)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
> | ||
{header} | ||
<ScrollableRegion aria-labelledby={dialogLabelId} className={classes.DialogOverflowWrapper}> | ||
|
There was a problem hiding this comment.
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