Skip to content

Commit

Permalink
[grid] Fix column spacing for nested containers (#43733)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Oct 3, 2024
1 parent 46869bc commit e74c659
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 172 deletions.
54 changes: 32 additions & 22 deletions packages/mui-material/src/Grid2/Grid2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,29 @@ export interface GridBaseProps {
offset?: ResponsiveStyleValue<GridOffset>;
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
* The level of the grid starts from `0` and increases when the grid nests
* inside another grid. Nesting is defined as a container Grid being a direct
* child of a container Grid.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* <Grid container> // level 0
* <Grid container> // level 1
* <Grid container> // level 2
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
* Only consecutive grid is considered nesting. A grid container will start at
* `0` if there are non-Grid container element above it.
*
* ```js
* <Grid> // level 0
* <Grid container> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* <Grid container> // level 0
* ```
*
* ```js
* <Grid container> // level 0
* <Grid>
* <Grid container> // level 0
* ```
*/
unstable_level?: number;
Expand Down Expand Up @@ -223,24 +228,29 @@ Grid2.propTypes /* remove-proptypes */ = {
]),
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
* The level of the grid starts from `0` and increases when the grid nests
* inside another grid. Nesting is defined as a container Grid being a direct
* child of a container Grid.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* <Grid container> // level 0
* <Grid container> // level 1
* <Grid container> // level 2
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
* Only consecutive grid is considered nesting. A grid container will start at
* `0` if there are non-Grid container element above it.
*
* ```js
* <Grid> // level 0
* <Grid container> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* <Grid container> // level 0
* ```
*
* ```js
* <Grid container> // level 0
* <Grid>
* <Grid container> // level 0
* ```
*/
unstable_level: PropTypes.number,
Expand Down
46 changes: 0 additions & 46 deletions packages/mui-material/src/PigmentGrid/PigmentGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ export interface GridBaseProps {
* Defines the offset of the grid.
*/
offset?: ResponsiveStyleValue<number> | undefined;
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
*
* ```js
* <Grid> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* ```
*/
unstable_level?: number;
/**
* Defines the vertical space between the type `item` components.
* It overrides the value of the `spacing` prop.
Expand Down Expand Up @@ -252,29 +229,6 @@ PigmentGrid.propTypes /* remove-proptypes */ = {
PropTypes.func,
PropTypes.object,
]),
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
*
* ```js
* <Grid> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* ```
*/
unstable_level: PropTypes.number,
/**
* Defines the `flex-wrap` style property.
* It's applied for all screen sizes.
Expand Down
27 changes: 16 additions & 11 deletions packages/mui-system/src/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,29 @@ Grid.propTypes /* remove-proptypes */ = {
]),
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
* The level of the grid starts from `0` and increases when the grid nests
* inside another grid. Nesting is defined as a container Grid being a direct
* child of a container Grid.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* <Grid container> // level 0
* <Grid container> // level 1
* <Grid container> // level 2
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
* Only consecutive grid is considered nesting. A grid container will start at
* `0` if there are non-Grid container element above it.
*
* ```js
* <Grid> // level 0
* <Grid container> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* <Grid container> // level 0
* ```
*
* ```js
* <Grid container> // level 0
* <Grid>
* <Grid container> // level 0
* ```
*/
unstable_level: PropTypes.number,
Expand Down
27 changes: 16 additions & 11 deletions packages/mui-system/src/Grid/GridProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,29 @@ export interface GridBaseProps {
offset?: ResponsiveStyleValue<GridOffset>;
/**
* @internal
* The level of the grid starts from `0`
* and increases when the grid nests inside another grid regardless of container or item.
* The level of the grid starts from `0` and increases when the grid nests
* inside another grid. Nesting is defined as a container Grid being a direct
* child of a container Grid.
*
* ```js
* <Grid> // level 0
* <Grid> // level 1
* <Grid> // level 2
* <Grid> // level 1
* <Grid container> // level 0
* <Grid container> // level 1
* <Grid container> // level 2
* ```
*
* Only consecutive grid is considered nesting.
* A grid container will start at `0` if there are non-Grid element above it.
* Only consecutive grid is considered nesting. A grid container will start at
* `0` if there are non-Grid container element above it.
*
* ```js
* <Grid> // level 0
* <Grid container> // level 0
* <div>
* <Grid> // level 0
* <Grid> // level 1
* <Grid container> // level 0
* ```
*
* ```js
* <Grid container> // level 0
* <Grid>
* <Grid container> // level 0
* ```
*/
unstable_level?: number;
Expand Down
7 changes: 6 additions & 1 deletion packages/mui-system/src/Grid/createGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ export default function createGrid(
{...other}
>
{React.Children.map(children, (child) => {
if (React.isValidElement(child) && isMuiElement(child, ['Grid'])) {
if (
React.isValidElement(child) &&
isMuiElement(child, ['Grid']) &&
container &&
child.props.container
) {
return React.cloneElement(child, {
unstable_level: (child.props as GridProps)?.unstable_level ?? level + 1,
} as GridProps);
Expand Down
Loading

0 comments on commit e74c659

Please sign in to comment.