Fix dialog background layout shift #5489
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes https://github.com/github/copilot-productivity/issues/2608
Background
Original PR: Prevents body scroll when Dialog is open #3547
This issue is caused by the
overscroll: hidden
behaviour which removes the scrollbar when the dialog is shown.As you can see, the layout noticeably shifts in the background.
current-behaviour.mov
I have explored several solutions, each with its own tradeoffs:
overscroll-behavior
I tried adding
overscroll-behavior: contain
on the dialog and ::backdrop element but that didn’t seem to work.Always showing the scrollbars
Using
overscroll-gutter: stable
oroverflow-y: scroll
will always show the scrollbar, which leaves a blank strip down the side of the page even when the scrollbar isn’t there, which can look awkward. But this is the most stable solution, likely to work on untested layouts.scrollbar-gutter.mov
Another avenue I tried was to add a padding or margin to the body to compensate for the missing scrollbar ala Bootstrap. It works but any fixed position components will still see a jitter as the top/right/bottom/left positioning doesn't respect padding or margin. It could be fixed programmatically by finding all fixed position elements and adding an offset
calc(100vw - 100%)
.Notice the background layout is unchanged.
padding-right.mov
Finally I followed the suggestion from StackOverflow.
It kinda works but could likely fail with other layouts.
position-fixed-solution.mov
Positioning inside a 100vw width parent
I haven't tried this: https://dev.to/rashidshamloo/preventing-the-layout-shift-caused-by-scrollbars-2flp
Leave it
I'm not sure if the solutions listed above is worth the problems they might caused.
References:
https://frontendmasters.com/blog/scroll-locked-dialogs/
Changelog
New
Changed
Removed
Rollout strategy
Testing & Reviewing
Merge checklist