mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.88k stars 32.26k forks source link

Grid2 nested Grids - missing variables #37476

Open PantherX99 opened 1 year ago

PantherX99 commented 1 year ago

I use nested Grid2 grids in my component. The nested grids get variables for each level with the number of level. Instead of just using the values of the parent grid, it mirrors the values in new variables. In my case, this results in the following variable being used but never being assigned. var(--Grid-columnsLevel2)

image

This is another grid inside another grid as an example. In the width property, the variable --Grid-columnsLevel1 is used but never assigned: ` <DatePicker sx={{width: "70%"}} label="Versandtag" value={props.datum} onChange={props.onChange} disablePast={true}/>

props.onChangeLieferterminFix(event.target.checked)}/>} label="Fix"/>

`

I do not know when this error occurred, because at the beginning it all worked fine. Switch back to previous commits does not help, so i do not think it's an error in my code.

Any suggestions?

Version: 5.13.3

hbjORbj commented 1 year ago

Can you copy/paste your code into a Codesandbox so I can debug it? Here is a template: https://codesandbox.io/s/mui-issue-latest-s2dsx

PantherX99 commented 1 year ago

Can you copy/paste your code into a Codesandbox so I can debug it? Here is a template: https://codesandbox.io/s/mui-issue-latest-s2dsx

https://codesandbox.io/s/strange-jackson-r4yznr

I hope I have done it right.

micky2be commented 1 year ago

Went through the code quickly and seems the level is getting incremented for each level of Grid regardless if it's a container or not. While the CSS variables are obviously created for the containers.

I can't know for sure as I'm using this library only for a couple of days, so I'm not too familiar with the source, but if not that, I shouldn't be too far off.

micky2be commented 1 year ago

In the mean time, for those who needs to use Grid2, make sure your Grid container is a direct child of another Grid container.

Or do the complete opposite. Put a non Grid element in between, like a Box. You won't get any inheritance but at least it won't break.

allicanseenow commented 1 year ago

I can replicate the issue with this code

<Grid container>
  <Grid>
     <Grid container>
        <Grid />

--Grid-columnsLevel1 was not set The quick solution for me is to put any component between the first Grid item and the second Grid container, including a Fragment, like this

<Grid container>
  <Grid>
    <>
      Grid container>
        <Grid />

This will prevent the second container from being treated as a nested Grid container