Skip to content

[Modal] Opening Modal causes the page to scroll #18793

@cvara

Description

@cvara

Rendering any component that internally relies on Modal, causes the page to jump/scroll.

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:

  1. scroll to find the button
  2. click the button to render the Popover
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGreat for first contributions. Enable to learn the contribution process.scope: modalChanges related to the modal.type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions