-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Description
Rendering any component that internally relies on Modal, causes the page to jump/scroll.
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate ([Popover] On mobile Chrome while zoomed, opening popover causes page to jump #17636 might be related though 🤔)
Current Behavior 😯
Rendering a component that is based on Modal (i.e. Popover) causes the page to scroll. This happens as long as:
- the scroll container has already scrolled
- the contents of the scroll container affect its total height
Expected Behavior 🤔
Scroll position should not change.
Steps to Reproduce 🕹
This example showcases the issue: https://codesandbox.io/s/zen-visvesvaraya-w7pp4
Steps:
- scroll to find the button
- click the button to render the Popover
- observe scroll position
Your Environment 🌎
| Tech | Version |
|---|---|
| Material-UI | v4.7.2 |
| React | 16.12 |
| Browser | Chrome 78, Firefox 71 |
Cause
The issue seems to be caused by the fact that the browser has the chance to render at least one frame after the scrollbar has been hidden - thus increasing the overall page width - but before the missing scrollbar width has been compensated by added padding, thus the content has been re-arranged to fit in a larger container, thus reducing the overall page height and causing the jump.
Grouping those 2 actions together seems to solve the issue, since both changes are applied on the same frame (happy to submit a PR with the fix).