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

[Grid2] Layout do not work the same way as Grid #44716

Closed
LoicMartinez opened this issue Dec 10, 2024 · 5 comments
Closed

[Grid2] Layout do not work the same way as Grid #44716

LoicMartinez opened this issue Dec 10, 2024 · 5 comments
Assignees
Labels
component: Grid The React component.

Comments

@LoicMartinez
Copy link

LoicMartinez commented Dec 10, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: codesandbox
  2. The sandbox start with Grid (old), on the first selector, select 5 or more item, layout work as intended
    mui-v6-old-grid
  3. Click on the top button to switch to the Grid2 component, select 5 items on the first selector, the layout is broken
    mui-v6-grid2-bug

Current behavior

No response

Expected behavior

No response

Context

The layout i'm using here may simplified (i could use one column grid and two row grid) but it need to be that way, there are a lot of style i did not include to be as simple as possible

Your environment

No response

Search keywords: Grid2 layout, Grid2, Grid

@LoicMartinez LoicMartinez added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 10, 2024
@zannager zannager added the component: Grid The React component. label Dec 10, 2024
@DiegoAndai DiegoAndai assigned DiegoAndai and unassigned siriwatknp Dec 10, 2024
@siriwatknp
Copy link
Member

Grid2 Layout do not work the same way as Grid

Yes, that's the point the building the Grid2. Based on your code, I think you are using the Grid incorrectly.

  • Why do you need a <Grid direction="column">? using <Stack> makes more sense.
  • The layout looks overcomplicated. Maybe if you can explain what kind of layout you want to achieve, then we can justify if the Grid is working correctly or not.

@siriwatknp siriwatknp added 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 12, 2024
@LoicMartinez
Copy link
Author

Thanks for the reply.

I updated the sandbox with spacing for the position.
I need to have 2 block of 4 selectors, one on the left and one on the right. With a bigger separation on the center. (hope you understand what i mean by that)

I'm only using Grid for this because it is state on the MUI documentation :

Stack is ideal for one-dimensional layouts, while Grid is preferable when you need both vertical and horizontal arrangement.

Also, I'm thinking, if a layout like that is broken with Grid2, what else could break ? It is supposed to create multi dimensional layout, it should probably not be broken like that on a still simple layout

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Dec 12, 2024
@aarongarciah aarongarciah changed the title Grid2 Layout do not work the same way as Grid [Grid2] Layout do not work the same way as Grid Dec 12, 2024
@DiegoAndai
Copy link
Member

Hey @LoicMartinez! Thanks for the report.

You're missing the size property on one of the nested grid containers:

 export default function NewGrid() {
   return (
     <div>
       <Grid2 container direction="row" spacing={4}>
         <Grid2 container direction="column" size={6} spacing={1}>
-          <Grid2 container direction="row" spacing={1}}>
+          <Grid2 container direction="row" spacing={1} size={12}>
             <Grid2 size={6}>
               <MultipleSelect />
             </Grid2>
             <Grid2 size={6}>
               <MultipleSelect />

By adding size={12} (size="grow" also works), we specify that this container should use all the space available. Here's your sandbox fixed: https://codesandbox.io/p/sandbox/issue-44716-fix-f2z8k2. Let me know if this fixes your issue.

If you're interested, I would suggest refactoring your code to be closer to our Grid2 demos. Instead of using direction 'row'|'column' and nesting Grid components, You could have one container like this demo: https://mui.com/material-ui/react-grid2/#basic-grid. This is the recommended way of using the Grid

@DiegoAndai DiegoAndai added 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 12, 2024
@LoicMartinez
Copy link
Author

Thanks for the help, it fixed my issue ! I'm gonna get ride of the direction props if it should not be used anymore for nested grid like this one !

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 16, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@LoicMartinez How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component.
Projects
None yet
Development

No branches or pull requests

4 participants