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

Dialogs cause the vertical scrollbar to disappear and reappear #6656

Closed
orenh1 opened this issue Apr 20, 2017 · 12 comments
Closed

Dialogs cause the vertical scrollbar to disappear and reappear #6656

orenh1 opened this issue Apr 20, 2017 · 12 comments
Labels
bug 🐛 Something doesn't work component: dialog This is the name of the generic UI component, not the React module!

Comments

@orenh1
Copy link

orenh1 commented Apr 20, 2017

Problem description

Every time a dialog appears (Dialog, Alert, Date Picker or Time Picker): if the document has a vertical scrollbar then it disappears, and reappears when the dialog is closed. This causes two annoying graphical glitches:

  1. The document reflows in the background (since it has more horizontal room)
  2. When the dialog is closed, it first jumps to the left a bit, and only then disappears

Link to minimal working code that reproduces the issue

This can be seen in the components demo. For example:

  1. Go to the Date Picker demo page at http://www.material-ui.com/#/components/date-picker
  2. Click on the first Date Picker field
  3. Observe:
    a) In the background, the GitHub icon in the top-right corner moves to the right when the Date Picker appears, and to the left when the Date Picker disappears.
    b) When the dialog is closed, it jumps to the left before disappearing.

Related issues

I believe that the following issue has the same cause (I created a new issue in order to use the proper issue template):

#5977 [DatePicker & TimePicker] Why does the DatePicker and TimePicker shift a bit to the side when closed?

@JFGHT
Copy link

JFGHT commented Apr 20, 2017

Are you sure this is not intended to be like that?

@orenh1
Copy link
Author

orenh1 commented Apr 20, 2017

Screen elements that jump around are a bad UI experience.

For an example of how this could work better, see the Dialog in the react-md project: https://react-md.mlaursen.com/components/dialogs . In react-md, when a dialog appears the document's scrollbar is just disabled; it's not removed. This eliminates the jump.

If you want to see what Google does, open an Android app that has a scrollbar and then open a dialog. You'll see that neither the background page nor the dialog jump. (E.g., in the Phone > Log screen).

@oliviertassinari oliviertassinari added the component: dialog This is the name of the generic UI component, not the React module! label Jun 8, 2017
@ncirkel
Copy link

ncirkel commented Jul 2, 2017

Another side effect for me was the page scrolling back to top whenever a dialog opened. As a workaround I've set body { overflow: visible !important; }, which cancels the inline overflow: hidden; that's being set on the body whenever a dialog is opened. For me, the original page being able to scroll in the background is actually not a problem at all.

@oliviertassinari
Copy link
Member

We have fixed that issue on the v1-alpha branch by applying an extra padding to compensate the missing scrollbar width. We are following the bootstrap solution. Adding overflow: hidden is important in order to prevent scroll on the underlying elements.

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work v1 labels Jul 14, 2017
@Aditya94A
Copy link

This is still happening for me (in the latest beta) when opening a dialog or even a Menu :/

@gregnb
Copy link
Contributor

gregnb commented Nov 1, 2017

I am also having this issue in the Dialog and the Popover component

@marshall-cho
Copy link

Same thing here, triggering Popover makes the whole page jump to the left due to padding-right: 15px; added to the body element...

@felansu
Copy link

felansu commented Mar 8, 2018

mar-08-2018 11-55-10

@rafamarqqqs
Copy link

rafamarqqqs commented Mar 31, 2018

I was having the same problem, but I've found a way to work around this by adding specific global styling to my index.html:

<style>
  html {
    overflow-y: auto;
    overflow-x: hidden;
  }

  body, #root {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
  }
</style>

The overflow rules applies to the html element and overrides the modal rules. Dunno if this is ok though

@oliviertassinari
Copy link
Member

Let's move the discussing to #10000.

@fastlogin
Copy link

I experienced the same problems working with Dialogs. The following is the only solution that I have tried that both removes the shifting of content and still locks the scroll of the underlying page/removes its scrollbar.

Solution:
Go to the outermost container div or any outermost div (any container that encapsulates your entire app) in your app and set its width to this:

width: calc(100vw - 1px);

1px can be substituted with 34px or any other low value. This will make it so that opening a Dialog will hide the scroll bar of the underlying page, if present, and will not create any sort of shift in the position of the content. Scrolling is still locked for the underlying page and scrolling is still possible for your dialog.

@AdrianMrn
Copy link

Setting the document's width to 100vw prevents this from happening:

html {
  height: 100svh;
  width: 100vw;
  overflow-y: scroll;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: dialog This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests