-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Support custom columns with nested grid #28743
Conversation
…er in grid item along with the breakpoint default fix
I think a unit test is needed in this PR. |
Cool. Will try to implement the unit test for the change. |
const columnSet = columnsProp || columnsContext || 12; | ||
|
||
// colums set with default breakpoint unit of 12 | ||
const columns = columnSet || 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest removing this line.
const columnsContext = React.useContext(GridContext); | ||
|
||
// setting prop before context to accomodate nesting | ||
const columnSet = columnsProp || columnsContext || 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const columnSet = columnsProp || columnsContext || 12; | |
const columns = columnsProp || columnsContext || 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll remove this line
@Devesh21700Kumar Hi, thanks for the PR. You can add the following unit test. A codesandbox (e.g., https://codesandbox.io/s/determined-brook-j2bur?file=/src/App.js) or a test is necessary for the maintainers to confirm that the PR is indeed fixing the relevant issue. diff --git a/packages/mui-material/src/Grid/Grid.test.js b/packages/mui-material/src/Grid/Grid.test.js
index 943f3bcaae..a6c1d6a74f 100644
--- a/packages/mui-material/src/Grid/Grid.test.js
+++ b/packages/mui-material/src/Grid/Grid.test.js
@@ -25,6 +25,24 @@ describe('<Grid />', () => {
const { container } = render(<Grid container />);
expect(container.firstChild).to.have.class(classes.container);
});
+
+ it('should apply the correct number of columns for nested containers', () => {
+ const { getByTestId } = render(
+ <Grid container columns={16}>
+ <Grid item xs={8}>
+ <Grid container columns={8} data-testid="nested-container">
+ <Grid item xs={8} />
+ </Grid>
+ </Grid>
+ </Grid>,
+ );
+ const container = getByTestId('nested-container');
+ // `columns` of nested container should have a higher priority than that of root container
+ // otherwise, max-width would be 50% in this test
+ expect(container.firstChild).toHaveComputedStyle({ maxWidth: '100%' });
+ });
}); |
Hey @hbjORbj , Thanks for the help. I've added the test and all the test suites and tests passed without showing any errors. |
@Devesh21700Kumar Can you run @siriwatknp Hey, argos test is failing. Where do you think this comes from? |
This one looks like there was a change in the icons of sorts These were the instances where the Snaps did not match |
ran prettier on the code for formatting
d18cacb
to
4c5ec67
Compare
This PR is not updated with master branch, that's all. I have updated it, waiting for green CIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! It's a great first pull request on MUI 👌 Thank you for working on it!
Closes #28554
A better representation of the above issue would be this
It can be clearly seen from the below image that the container inside the item uses the spacing props of the parent
The correct case should have been this
This can be fixed by just some boolean fixes
The prop had to be put before the value obtained for Gridcontext in the OR operation for it to be used first
The breakpoint unit 12 had to be set later so that it can be used as a default provided the earlier two parameters are null