Skip to content

Commit

Permalink
check container first
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Sep 12, 2024
1 parent 2a45a3a commit 961fa8b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
"unist-util-visit": "^2.0.3",
"yargs": "^17.7.2"
},
"packageManager": "pnpm@9.7.1",
"packageManager": "pnpm@9.10.0",
"engines": {
"pnpm": "9.7.1"
"pnpm": "9.10.0"
},
"resolutions": {
"@babel/core": "^7.24.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/pigment-css-react/src/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const Grid = React.forwardRef(function Grid(
ownerState={ownerState}
>
{React.Children.map(children, (child) => {
if (React.isValidElement(child) && isGridComponent(child)) {
if (container && React.isValidElement(child) && isGridComponent(child)) {
return React.cloneElement(child, {
unstable_parent_columns: selfColumns,
unstable_parent_column_spacing: selfColumnSpacing,
Expand Down
13 changes: 13 additions & 0 deletions packages/pigment-css-react/tests/Grid/Grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ describe('Pigment CSS - Grid', () => {
expect(getByTestId('grid-container')).not.to.equal(null);
expect(getByTestId('grid-item')).not.to.equal(null);
});

it('should not pass down unstable props for non container Grid', () => {
function Child({ unstable_parent_columns }) {
return <div>{unstable_parent_columns}</div>;
}
Child.muiName = 'Grid';
const { queryByText } = render(
<GridOutput>
<Child />
</GridOutput>,
);
expect(queryByText('12')).to.equal(null);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const Grid = React.forwardRef(function Grid(
ownerState={ownerState}
>
{React.Children.map(children, (child) => {
if (React.isValidElement(child) && isGridComponent(child)) {
if (container && React.isValidElement(child) && isGridComponent(child)) {
return React.cloneElement(child, {
unstable_parent_columns: selfColumns,
unstable_parent_column_spacing: selfColumnSpacing,
Expand Down

0 comments on commit 961fa8b

Please sign in to comment.