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] Fix column spacing for nested containers #43733

Merged
merged 21 commits into from
Oct 3, 2024
Merged

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Sep 12, 2024

  • Only increase the level if the nested grid is a container inside a container as per the docs
  • The ...LevelX variable doesn't behave correctly. It creates correct gaps on containers, but children don't use the correct variable to calculate their width. The JS logic seems sound though, I just translated it to CSS with a -parent- variable on the container children. It behaves a lot better.
  • Abstract the spacing styles generation logic, just like the var consumption logic already was.
  • Incidentally this results in a bundle size reduction

Closes #43707

@Janpot Janpot added bug 🐛 Something doesn't work component: Grid The React component. labels Sep 12, 2024
@mui-bot
Copy link

mui-bot commented Sep 12, 2024

Netlify deploy preview

https://deploy-preview-43733--material-ui.netlify.app/

@mui/joy: parsed: -0.11% 😍, gzip: -0.10% 😍
@material-ui/core: parsed: -0.09% 😍, gzip: -0.06% 😍
Grid2: parsed: -0.68% 😍, gzip: -0.32% 😍
@mui/joy/Grid: parsed: -0.76% 😍, gzip: -0.32% 😍
@material-ui/system: parsed: -0.64% 😍, gzip: -0.21% 😍

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 28508f9

@Janpot Janpot marked this pull request as ready for review September 13, 2024 10:11
@Janpot Janpot requested a review from a team September 13, 2024 10:11
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fro working on this @Janpot!

if (
React.isValidElement(child) &&
isMuiElement(child, ['Grid']) &&
container &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think checking for container is correct: https://github.com/mui/material-ui/blob/be183c4d560a8343f82c284dd407f618b54f06a2/packages/mui-system/src/Grid/Grid.tsx#L111C6-L128C29. The level should be increased regardless.

Copy link
Member Author

@Janpot Janpot Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual level number has no meaning anymore after this change. The only way it now is being used is to check whether it's either 0 or not. It's now only used to find out whether the current grid is nested (as per what the docs define as nested, container inside of container) or top-level. The new logic doesn't work anymore if you remove this condition. I believe we need to update that comment you refer to instead 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, that makes sense. Yes, if the logic is changed, let's update the comment.

@Janpot Janpot requested a review from DiegoAndai September 17, 2024 16:17
@Janpot Janpot requested a review from mnajdova October 1, 2024 16:47
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final minor comment, but otherwise looks good 🙌🏼

I think we can use the same approach for the Pigment Grid to simplify its implementation.

* ```js
* <Grid container> // level 0
* <Grid>
* <Grid container> // level 0
* ```
*/
unstable_level?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PigmentGrid doesn't have the unstable_level prop (reference), it shouldn't have been added. May I ask you to remove it? (or if you prefer, I can do it in a separate PR, let me know)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Janpot Janpot requested a review from DiegoAndai October 3, 2024 17:00
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Janpot!

@Janpot Janpot merged commit e74c659 into mui:master Oct 3, 2024
19 checks passed
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 this pull request may close these issues.

Nested grids for v2 are not behaving the same as in v1
3 participants