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

[Grid] Wrong grid item width for nested containers with custom columns prop #30209

Closed
2 tasks done
AlexKrupko opened this issue Dec 14, 2021 · 10 comments · Fixed by #31340
Closed
2 tasks done

[Grid] Wrong grid item width for nested containers with custom columns prop #30209

AlexKrupko opened this issue Dec 14, 2021 · 10 comments · Fixed by #31340
Labels
bug 🐛 Something doesn't work component: Grid The React component.

Comments

@AlexKrupko
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Cell width is calculating incorrect for nested containers with custom columns prop.

<Grid container columns={11}>
    <Grid item xs={4}>
        <Grid container>
            <Grid item xs={12}>
                Calculated width is 109.090909%
            </Grid>
        </Grid>
    </Grid>
    <Grid item xs={4}>
        <Grid container columns={12}>
            <Grid item xs={12}>
                Calculated width is 109.090909%
            </Grid>
        </Grid>
    </Grid>
    <Grid item xs={3}>
        ...
    </Grid>
</Grid>

So, the value of columns prop from top-level container is used for calculating all item widths. All nested columns props are ignored.

I guess, this issue is related to #28554

Expected behavior 🤔

Cell width should be calculating based on columns prop value of the parent grid container.

Steps to reproduce 🕹

No response

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 11.6.1
  Binaries:
    Node: 16.8.0 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 7.21.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Edge: Not Found
    Firefox: 92.0
    Safari: 15.1
  npmPackages:
    @emotion/react: ^11.5.0 => 11.6.0 
    @emotion/styled: ^11.3.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.55 
    @mui/icons-material: ^5.0.4 => 5.1.1 
    @mui/lab: ^5.0.0-alpha.55 => 5.0.0-alpha.55 
    @mui/material: ^5.1.0 => 5.1.1 
    @mui/private-theming:  5.1.1 
    @mui/styled-engine:  5.1.1 
    @mui/system:  5.1.1 
    @mui/types:  7.1.0 
    @mui/utils:  5.1.1 
    @types/react: ^17.0.0 => 17.0.35 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    typescript: ^4.4.3 => 4.4.4 
@AlexKrupko AlexKrupko added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 14, 2021
@michaldudak
Copy link
Member

I'm not sure if I understand the problem. I tried to reproduce it in codesandbox using the code you provided (I used 5-column grid for better visibility): https://codesandbox.io/s/proud-shape-gz9n1?file=/src/Demo.tsx

The whole grid is 500px wide and the grey and green cells have 200px and 100px respectively, as I expected. Could you explain in more detail what you would expect?

@michaldudak michaldudak added component: Grid The React component. status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 17, 2021
@AlexKrupko
Copy link
Author

Hi @michaldudak ,
please check the calculated value of max-width property for nested grid items.
Screen Shot 2021-12-21 at 22 32 51

@michaldudak
Copy link
Member

@AlexKrupko indeed, this doesn't look correct.

@michaldudak michaldudak reopened this Jan 3, 2022
@michaldudak michaldudak added bug 🐛 Something doesn't work and removed status: waiting for author Issue with insufficient information labels Jan 3, 2022
@ConnerAiken
Copy link

@alonmatthew and I found if you set the nested columns grid explicitly to: <Grid columns={12}>, it will still inherit the parent grid column count.

However, if you set either of these, it will work:

  • <Grid columns={{xs: 12}}/>
  • <Grid columns={'12'}/>

@ConnerAiken
Copy link

ConnerAiken commented Jan 12, 2022

@michaldudak Is there somewhere in the documentation that says Grid's should inherit their parent Grid container's column prop? IMO this is not intuitive.

I would expect the nested grid here to be 12 columns, as is default:
https://codesandbox.io/s/nestedgrid-material-demo-forked-ghqye

Here's an example of trying to manually override it in a basic shorthand use case but it doesn't work:
https://codesandbox.io/s/nestedgrid-material-demo-forked-u65ly

Hacky version to get it to actually override:

@michaldudak
Copy link
Member

No, I believe it shouldn't work like that and it's a bug. The columns prop should behave the same no matter if it's a top-level or nested grid. Would you like to take a look at it and contribute a fix?

@ConnerAiken
Copy link

@michaldudak Sure. Thanks for clarifying.

@boutahlilsoufiane
Copy link
Contributor

Hi @michaldudak, I think @ConnerAiken isn't available, I will work on this.

@ConnerAiken
Copy link

Thanks @boutahlilsoufiane, my 9-5 is blocking me from helping.

@boutahlilsoufiane
Copy link
Contributor

Hi @michaldudak, I created a PR for this, could you please review It? thanks a lot.

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: Grid The React component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants