Skip to content
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

[Bug] Modals move other UI elements when opening and closing #81

Closed
rickstaa opened this issue Feb 25, 2021 · 7 comments
Closed

[Bug] Modals move other UI elements when opening and closing #81

rickstaa opened this issue Feb 25, 2021 · 7 comments

Comments

@rickstaa
Copy link

rickstaa commented Feb 25, 2021

Version

1.9.0

Reproduction link

https://demos.creative-tim.com/material-kit-pro-react/#/components

Operating System

Ubuntu 20.04, windows 10

Device

Hp Zbook G5

Browser & Version

Chrome v8.0.4324.150, firefox v85.0.1

Steps to reproduce

  1. Open the material-kit-pro-react demo website.
  2. Go to the components page.
  3. Click one of the modals.
  4. See the header and right dots jump.

What is expected?

I expected the other UI components to stay still when toggling the modal.

What is actually happening?

Currently, some elements are moved when the modal is opened and closed.

modal_problem


Solution

I did not yet find a solution to this problem. It looks like it is related to the scrollbar. I tried the solutions in this stackoverflow post but they don't seem to work.

Additional comments

Seems to be related to:

@einazare
Copy link
Contributor

Hello there, @rickstaa ,

Unfortunately, this cannot be solved.
It is because on Windows devices, the Scrollbar, when you open a modal, it disappears. And there is no way of solving this. It is the browser default behavior.

Best,
Manu

@rickstaa
Copy link
Author

@einazare I think your right. It seems to occur on Linux and Windows. I think if this is solvable it should be done in the material-UI repository. You can follow the related issue here.

@rickstaa
Copy link
Author

@einazare Actually it seems they already fixed in Material-UI v5.

@Tetedeiench
Copy link

To anyone coming accross this issue, this is caused by the Dialog setting "overflow-y: hidden" when appearing on the body, which causes the scrollbar to disappear.

A fix for me was to set 'overflow-y':'auto !important' on the body element (CSS).

It's probably not the best fix, but it does the trick wonderfully for me !

@rickstaa
Copy link
Author

@Tetedeiench Thanks a lot for uploading the fix. I'm glad that your solution worked out for you. Maybe I'm doing it wrong but for me, in the new chrome/firefox browsers, this, unfortunately, does not work. Adding the overflow-y: auto !important property adds extra padding for the scrollbar but still moves the elements.

problem-overflow

@Tetedeiench
Copy link

Tetedeiench commented Feb 28, 2021

Hi @riskstaa,

Here's the problem reproduced on my (currently in dev) website :
scrollbar dialog issue

And with the fix i mentioned :
scrollbar dialog issue fixed

I'm NOT an expert in frontend dev (quite the contrary), but the issue seems to be the dialog forcing overflow-y to hidden when appearing.

This in turn hides the scrollbar if any was displayed before the dialog appeared, which moves the page behind the dialog to deal with this.

Of course, make sure you force overflow-y to any value you currently use with the dialog closed. I use auto personally !

I think in your case, looking at your CSS, simply forcing "overflow: hidden !important" will prevent the dialog from fiddling with it when appearing and things should go smooth. Also, make sure you're doing the change before opening the dialog, as changing this value when the dialog is opened will make things shake ;)

The fix is just making sure the scrollbar stays in place when the dialog is opened.

Edits : lots of spelling mistakes and clarifications, sorry.

@WROIATE
Copy link

WROIATE commented Jul 7, 2023

@Tetedeiench Thanks a lot for uploading the fix. I'm glad that your solution worked out for you. Maybe I'm doing it wrong but for me, in the new chrome/firefox browsers, this, unfortunately, does not work. Adding the overflow-y: auto !important property adds extra padding for the scrollbar but still moves the elements.

try add padding-right: 0 !important to body css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants