I have a simple Material UI dialog containing a grid, and it has a scrollbar that can scroll a few pixels even though the screen is big enough to contain the whole thing.
<Dialog open={isOpen} onClose={() => changeIsOpen(false)}>
<DialogContent>
<Grid container spacing={3}>
<Grid item xs={12} sm={6}>
<TextField label="First Name" fullWidth />
</Grid>
<Grid item xs={12} sm={6}>
<TextField label="Last Name" fullWidth />
</Grid>
<Grid item xs={12}>
<TextField label="Username" fullWidth />
</Grid>
</Grid>
</DialogContent>
<DialogActions>
<Button
color="secondary"
variant="contained"
onClick={() => changeIsOpen(false)}
>
Cancel
</Button>
<Button
color="primary"
variant="contained"
onClick={() => changeIsOpen(false)}
>
OK
</Button>
</DialogActions>
</Dialog>
This code is at https://codesandbox.io/s/cool-cherry-or0r8 for you to see.
I don't want to use overflow: hidden
, because if the page is too small, there will be a scrollbar and that's correct. (Not likely to happen in this toy example with 3 fields, but easily possible in larger dialogs).
I think the problem has something to do with interactions between flexbox and the negative margins that <Grid>
uses, but I can't quite work it out.