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] Support custom columns with nested grid #28743

Merged
merged 3 commits into from
Oct 20, 2021

Conversation

Devesh21700Kumar
Copy link
Contributor

@Devesh21700Kumar Devesh21700Kumar commented Oct 1, 2021

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

image

The correct case should have been this

image

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

…er in grid item along with the breakpoint default fix
@mui-pr-bot
Copy link

mui-pr-bot commented Oct 1, 2021

Details of bundle changes

Generated by 🚫 dangerJS against e069cd6

@siriwatknp siriwatknp changed the title using context value after props to accomodate nesting of grid container in grid item along with the breakpoint default fix [Grid] support custom columns with nested grid Oct 1, 2021
@siriwatknp
Copy link
Member

I think a unit test is needed in this PR.

@Devesh21700Kumar
Copy link
Contributor Author

I think a unit test is needed in this PR.

Cool. Will try to implement the unit test for the change.

@eps1lon eps1lon added component: Grid The React component. new feature New feature or request PR: needs test The pull request can't be merged labels Oct 4, 2021
const columnSet = columnsProp || columnsContext || 12;

// colums set with default breakpoint unit of 12
const columns = columnSet || 12;
Copy link

Choose a reason for hiding this comment

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

This line is redundant.

Copy link
Member

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.

@siriwatknp siriwatknp mentioned this pull request Oct 6, 2021
1 task
const columnsContext = React.useContext(GridContext);

// setting prop before context to accomodate nesting
const columnSet = columnsProp || columnsContext || 12;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const columnSet = columnsProp || columnsContext || 12;
const columns = columnsProp || columnsContext || 12;

Copy link
Contributor Author

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

@hbjORbj
Copy link
Member

hbjORbj commented Oct 12, 2021

@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%' });
+    });
   });

@Devesh21700Kumar
Copy link
Contributor Author

@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.

@hbjORbj
Copy link
Member

hbjORbj commented Oct 13, 2021

@Devesh21700Kumar Can you run yarn prettier:all and push again? test_static is failing.

@siriwatknp Hey, argos test is failing. Where do you think this comes from?

@Devesh21700Kumar
Copy link
Contributor Author

Devesh21700Kumar commented Oct 13, 2021

@Devesh21700Kumar Can you run yarn prettier:all and push again? test_static is failing.

@siriwatknp Hey, argos test is failing. Where do you think this comes from?

image

image

This one looks like there was a change in the icons of sorts

These were the instances where the Snaps did not match

@siriwatknp
Copy link
Member

Hey, argos test is failing. Where do you think this comes from?

This PR is not updated with master branch, that's all. I have updated it, waiting for green CIs.

Copy link
Member

@hbjORbj hbjORbj left a 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!

Copy link
Member

@mnajdova mnajdova left a 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!

@mnajdova mnajdova changed the title [Grid] support custom columns with nested grid [Grid] Support custom columns with nested grid Oct 20, 2021
@mnajdova mnajdova merged commit ee251a8 into mui:master Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. new feature New feature or request PR: needs test The pull request can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Grid] Nested containers ignore columns prop
7 participants