-
-
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
[docs] Overriding with classes is a bit unclear #9050
Comments
I agree, it would be good to update the documentation to clarify the behavior. |
@pandaiolo Do you want to update the documentation? |
I'll give it a try, probably this week end or next one |
I came across this issue as well because I assumed this is possible or even the right way to do it. @oliviertassinari Looking at your answers to similar issues I can see you recommend using styling with a higher specificity instead, i.e. Is this the intended way to customize internal material-ui styles? The reason for this are CSS modules I am using:
So can there be an option to modify this behaviour of |
@ottosichert One way to increase the specificity is to change the injection order of the CSS. We have one mechanism to do so. Let us know if this fix your issue. |
Thanks for the hint. So to the answer to my question is it was (and will?) never be intended to replace internal classes. We have to stick to overriding solutions. @pandaiolo can you add this information to the docs as well if you give it a try? :) |
@ottosichert I have missed this sentence, it's something we have been discussing under #6218. It's a different topic. |
Adding a comment here for posterity. If you're using JSS and you want to override Material-UI styles you can, as @oliviertassinari mentioned, change the injection order to achieve this. However the latest Material UI build is not using the latest react-jss build. It's using a fork of it. So if you're using react-jss in your project the following isn't going to help:
instead you're going to need to use the material-ui HOC like so:
If you use I would put up a PR to add this to the docs but from what I understand this situation is temporary. Material UI is planning on modifying and then incorporating the latest react-jss build into the project and once that happens people should just be able to look at the react-jss docs on stylesheet injection order to solve this issue. |
@pandaiolo Does the current wording make things any clearer? |
You were faster than me... thank you :)
That sentence is very clear to me and makes the underlying logic more understandable 👍 |
Thanks. |
@mbrookes Great :) ! |
Just in case some one else find this issue later. I've created a component to simplify the material ui's css over writing process. You just need to wrap your whole application in this Eg:
Live sample is here: Live examples |
This is just a discussion over documentation of v1.
In this section : https://material-ui.com/customization/overrides/#overriding-with-classes it seems in both the text description, and the example, that the classes override replace the default one.This is not very intuitive as classes are string, not objects that can merge, which is why I thought it worked that way in the first place.
An explicitly description of how it works could make things clearer, . ie. the styles objects pointed by both the overriding class name and the default one, are merged together.
What do you think?
The text was updated successfully, but these errors were encountered: