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

[DataGrid] Add overridesResolver #2995

Merged
merged 9 commits into from
Oct 27, 2021

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Oct 26, 2021

I think these are all the places where it needs to be added. There are other places where styled has been used but they are to change specific styles of a core component and we don't expose that slot in gridClasses.

Also, I wasn't able to break these demos https://deploy-preview-2995--material-ui-x.netlify.app/components/data-grid/style/#styling-cells 👀

@DanailH DanailH added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Oct 26, 2021
@DanailH DanailH self-assigned this Oct 26, 2021
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

Could you rebase/merge with next? I already fixed the argos screenshot, it should not fail on this one.

@@ -5,6 +5,7 @@ import { gridClasses } from '../../gridClasses';
export const GridRootStyles = styled('div', {
name: 'MuiDataGrid',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
Copy link
Member

@m4theushw m4theushw Oct 26, 2021

Choose a reason for hiding this comment

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

If we only apply the styles from root, the remaining styles won't work, which would be a breaking change. See https://codesandbox.io/s/datagriddemo-material-demo-forked-wdcrd?file=/demo.js

What do you think about manually fetching the overrides and applying them to each "slot"? The main trade-off I see is that it raises the specificity to 2, while with @mui/styles it was 1. However, the overrides will always win because they are applied at the end.

diff --git a/packages/grid/_modules_/grid/components/containers/GridRootStyles.ts b/packages/grid/_modules_/grid/components/containers/GridRootStyles.ts
index d5c60417..d061de1a 100644
--- a/packages/grid/_modules_/grid/components/containers/GridRootStyles.ts
+++ b/packages/grid/_modules_/grid/components/containers/GridRootStyles.ts
@@ -1,4 +1,4 @@
-import { CSSInterpolation } from '@mui/system';
+import { CSSInterpolation, CSSObject } from '@mui/system';
 import { darken, lighten, alpha, styled } from '@mui/material/styles';
 import { gridClasses } from '../../gridClasses';

@@ -7,6 +7,8 @@ export const GridRootStyles = styled('div', {
   slot: 'Root',
   overridesResolver: (props, styles) => styles.root,
 })(({ theme }) => {
+  const overrides = theme.components?.MuiDataGrid?.styleOverrides;
+
   const borderColor =
     theme.palette.mode === 'light'
       ? lighten(alpha(theme.palette.divider, 1), 0.88)
@@ -26,6 +28,7 @@ export const GridRootStyles = styled('div', {
     flexDirection: 'column',
     [`&.${gridClasses.autoHeight}`]: {
       height: 'auto',
+      ...overrides?.autoHeight as CSSObject
     },
     [`& .${gridClasses.main}`]: {
       position: 'relative',

Copy link
Member

@m4theushw m4theushw Oct 26, 2021

Choose a reason for hiding this comment

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

The TablePagination component applies the overrides from other slots in the overrides resolver: /~https://github.com/mui-org/material-ui/blob/b6cdaaf1a7f60de9ed66a491b7477fad19429905/packages/mui-material/src/TablePagination/TablePagination.js#L76

I think we can adopt the same pattern and ignore my suggestion. @mnajdova could help.

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
overridesResolver: (props, styles) => styles.root,
overridesResolver: (props, styles) => {
return [
{ [`& .${gridClasses.autoHeight}`]: styles.autoHeight },
styles.root,
];
},

I would suggest doing something like this. Using an array, instead of spreading objects, means that emotion is responsible for merging them correctly. We should have this in all components, but seems like in the TablePaginationToolbar it was not converted, I will fix this. Take a look for example how it is done in the Accordion component - /~https://github.com/mui-org/material-ui/blob/master/packages/mui-material/src/Accordion/Accordion.js#L38

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, thanks for the examples. I update the resolver. Seems to be working correctly now.
@m4theushw I removed some classes that were left behind when you reworked the virtualization. They were not used anywhere.

@DanailH DanailH requested review from mnajdova and m4theushw October 27, 2021 10:42
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

Looks good. The example is working again: https://codesandbox.io/s/datagriddemo-material-demo-forked-wdcrd?file=/demo.js

Only a few small things left but this one can be merged.

DanailH and others added 3 commits October 27, 2021 14:23
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
…lH/material-ui-x into bug/DataGrid-add-overridesResolver
@DanailH
Copy link
Member Author

DanailH commented Oct 27, 2021

I'll merge this even tho the roving index e2e test is failing. That is the only problem.

@DanailH DanailH merged commit 2209ffc into mui:next Oct 27, 2021
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: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants