-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Problem with the latest MUIv5 and classes/withStyles overrides of nested elements #62
Comments
I checked MUI's issues as well and the only partially related thing I found is mui/material-ui#30727 But it's about "state" rules, while in my case I'm overriding sub-component (slot). I also took a look on the implementation of But then I'm not sure why |
Hi @synaptiko, I might be able to do something about it but I am not sure. Is the problem that the collor in the PS: Maybe related: #38 |
The issue is specifically about sub-component. Even if Thank you, I'll try to get help from MUI. |
Is it that (1) doesn’t take precedence over (2) ? deleteIcon: {
color: theme.palette.primary.contrastText, // (2)
'&:hover': {
color: `${theme.palette.primary.contrastText}6`, // (1)
},
}, Or is it that neither (1) nor (2) take precedence over an internal MUI style that defines |
@garronej It's about specificity of what's generated by Here are the generated styles: What's coming from MUI is |
OK, thank you for the extra details. In defense of the MUI team, if they are facing all theses specificity issues it is because they are allowing users to use |
Got it, I understand it's not an easy job to support customization, especially with more than one CSS engine. In any case, thanks for you help, feel free to close this issue and let's see if someone from MUI can help or if we just need to refactor the code to increase specificity. |
I'm interested to have the follow up on this. |
Hello,
when I created this PR #54 we were still using MUIv4. We are using overrides with
classes
prop andwithStyles
of MUI components a lot and since we started migrating to MUIv5, I've noticed something strange.I've create a demo here:
I followed the recommended steps from both
tss-react
and MUI projects to eliminate issues with the setup.The problem in a nutshell is the following, when you have a component with sub-elements and you'd like to override default styles (let's say color or background color), one would expect to use what was possible in MUIv4:
But it doesn't work because of CSS selector specificity:
The only solution I found is with:
Unfortunately it requires a lot of refactoring in our code and it's also quite hard to reason about, you need to know that you are fighting with specificity here (which I assumed that
emotion
-based solution should help to avoid).I'm not 100% sure if it's a problem in
tss-react
itself or if it's more about how MUIv5 handlesclasses
props.The text was updated successfully, but these errors were encountered: