Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-UI adds padding to the body tag when a dialog is opened

I am using Material-UI in my react application. Recently, I updated my packages to the latest version. Now, when I open a dialog in my application, padding-right: 17px; will be added to the body tag. I also checked the Material-UI site, and this is happening on their website too with dialogs.

Is this a bug with the new version of Material-UI?

How can I remove this padding from the body tag when opening a dialog?

Update: This padding will be added to the body tag with Drawer, Menu, Dialog, and Popover components.

like image 298
F-Fardin Avatar asked Mar 14 '20 11:03

F-Fardin


Video Answer


4 Answers

as it was mentioned by @Reins you can use disableScrollLock property. The thing is sometimes this property is nested on components's input so you need to use inputProps in order to set it. Here is an example with Select component:

<Select
    className={classes.select}
    inputProps={{MenuProps: {disableScrollLock: true}}}
    ...
/>

Sometimes you may want to dig into MUI codebase in order to figure out how to apply some nested element's properties.

like image 137
mariano_c Avatar answered Oct 18 '22 01:10

mariano_c


Just give disableScrollLock={ true }. I think it will solve the issue because I had the same.

like image 43
Jobin Varghese Avatar answered Oct 18 '22 01:10

Jobin Varghese


I added disableScrollLock prop to my Dialog Component. It worked.

like image 6
whis Avatar answered Oct 18 '22 02:10

whis


You can use a mui-fixed class for handling this issue, it's helpful for me.

Here is a link for material UI mui-fixed document : https://material-ui.com/getting-started/faq/#why-do-the-fixed-positioned-elements-move-when-a-modal-is-opened

Hope this will help anyone.

like image 4
Jasmin Shaikh Avatar answered Oct 18 '22 01:10

Jasmin Shaikh