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] The CSS customization section is misleading #1163

Closed
2 tasks done
oliviertassinari opened this issue Mar 4, 2021 · 5 comments · Fixed by #1450
Closed
2 tasks done

[DataGrid] The CSS customization section is misleading #1163

oliviertassinari opened this issue Mar 4, 2021 · 5 comments · Fixed by #1450
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted

Comments

@oliviertassinari
Copy link
Member

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

  1. The "implementation of the component style " link in https://material-ui.com/api/data-grid/#css is a 404
  2. The data grid fails the classes prop conformance: https://codesandbox.io/s/material-demo-forked-6n2eu?file=/demo.tsx

Screenshot 2021-03-04 at 11 00 24

Expected Behavior 🤔

  1. A working link
  2. A working classes prop

Context 🔦

The issue was reported by a user under the wrong channel ([email protected]).

Your Environment 🌎

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Order id 💳

21793

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work docs Improvements or additions to the documentation component: data grid This is the name of the generic UI component, not the React module! labels Mar 4, 2021
@holdenmatt
Copy link

I also just hit this trying to add classes to a DataGrid and found this issue.

I'll use global CSS as a workaround for now, but am otherwise using CSS modules so having a working classes prop would be great!

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Mar 10, 2021

@holdenmatt We only plan to include classes.root as the data grid relies heavily on one level descendant CSS selectors. Would it work for you?

@holdenmatt
Copy link

I'm adding some CSS to customize a few classes like .MuiDataGrid-cell and .MuiDataGrid-columnSeparator.
AFAIK, I can't do that using only className or classes.root?

I ended up using a global SCSS file with nested selectors, which works fine. Slight preference for having a method that would let me define scoped styles with my component rather than globally. But if not, this works fine.

@oliviertassinari oliviertassinari added the ready to take Help wanted. Guidance available. There is a high chance the change will be accepted label Mar 13, 2021
@oliviertassinari
Copy link
Member Author

@holdenmatt Correct. If you are used to CSS modules, you could still apply the root class name to the root of the data grid, and then, use global descendant CSS selectors to target what you need. For instance, to get something like this at the end:

.a12vt .MuiDataGrid-cell {
  background-color: red;
}
<DataGrid className="a12vt" />

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Mar 13, 2021

I have added the "good to take" label as the solution should be as simple as:

  1. Replacing https://github.com/mui-org/material-ui-x/blob/master/packages/grid/_modules_/grid/components/styled-wrappers/GridRootStyles.ts with the correct URL.
  2. Adding a classes prop with a single root key. This is for consistency with the other components.

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! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants