-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Autocomplete custom styles get overwritten by MUI styles (v5) #30294
Comments
You should use the |
I am already using that selector.
I forgot to mention I am using CSS modules, but the other components seem to be working fine. There was also a similar problem in a page where I was importing React-Select, but with the performance upgrades to the Selects in MUI5 I don't need React-Select anymore, so I solved it just by removing it. This is my _app.page.tsx
|
You are not based on the code. You should use something like: styles.css .listbox {
+ // Need to bump the specificity on the options
+ & .MuiAutocomplete-option {
+ // the menuItem styles
+ }
} <Autocomplete
id={name}
classes={{
- option: styles.menuItem,
listbox: styles.menuList,
noOptions: styles.noOptions,
groupLabel: styles.headerItem,
}} /> If there are problems please create a codesandbox, otherwise, it's hard to iterate and verify that it works. cc @hbjORbj probably these are more opportunities for improving the migration guide. |
So that's an intended change then? I never had to target '.Mui' selectors before, the classes property used to be enough to target exactly what I needed. |
Yes, we just haven't documented it correctly. I would assume the same would go for the select. If I was using CSS modules, I would always specify all styles with sub-selectors inside the root class name. It's simpler and there won't be any surprises. |
@mnajdova ok thanks for the help :) |
@mnajdova correct me if I'm wrong but this makes using compose way harder than before, since we can only use 1 level selectors, so .listbox .item { compose: etc from "./etc" } doesnt work anymore. Also i was able to make this work, but in order to do it, this was what I had to do:
Seems way too convoluted. I tried to do it as you said but it didn't work. Heres a codesandbox showing the problem: https://codesandbox.io/s/autocomplete-css-modules-demo-o1hsk |
Will check it tomorrow |
Here is a working example @UnderTheMoonspell https://codesandbox.io/s/autocomplete-css-modules-demo-forked-udjpj?file=/src/CssModulesSlider.module.css You were close :) When you use CSS modules you need to specify the selector for the subclass and pass it along. Basically you are again passing all the classes as before, you just bump the specificity for the styles for the option, by rising the selector:
|
@mnajdova ok thanks for the help, this doesnt change the fact that it now becomes harder to use "composes" which is one of the nice features of CSS Modules. Also I am having a very hard time trying to do the same for the Select component: The highest specitivity here is Mui's and it's based on a MuiInput + MuiSelect. That MuiInput is not even costumizable as seen here: And so, in my use case I have a base select component, which then I use to create, for example, a country select, but this makes overriding a nightmare (to be honest, as I see it, makes it impossible without using !important). |
It's not perfect that you need to bump the specificity here, we should work on improving the DX for customizing the |
@mnajdova how would I bump the specificity here? |
We are also experiencing the same issues. In MUI 4 our styled components would take priority over the base styles of the components. Now that we have to include even more specificity, it is quite a nightmare. Is there any way we can get this reverted so that styled components take priority? (We also converted from styled-components to emotion). Is there any plan to do this with a timeline? Our team is currently thinking of reverting back to MUI 4 until some of these issues are resolved in a better manner. This affects all of our components, not just autocomplete. |
@Cwittofur if you are using only emotion there shouldn't be any issues. You can even use the If you can provide an example usage that you have, or create a simple codensadbox/repository to showcase the problem, I can help with it. |
We're probably missing something, but Dialog doesn't seem to append the custom styles at the end? In this codesanbox, we create a custom Paper component and use it in Dialog: const StyledPaper = styled(Paper)`
background-color: pink;
max-width: revert; // <-- doesn't work
width: 1200px;
`;
<Dialog ... PaperComponent={StyledPaper}>
...
</Dialog> But somehow our custom style rules are not appended at the end of the Paper class, so we can't override However, if we wrap our custom style with const StyledPaper = styled(Paper)`
& { // <-- net change
background-color: pink;
max-width: revert; // <-- works now!
width: 1200px;
}
`; Question: Is it normal that sometimes custom styles are appended at the end of the rules and sometimes it's not? Our suspicion is that perhaps our custom styles are in the middle of the Thank you! CC: @mnajdova please kindly help take a look at this if possible, since resolving/clarifying this will help our company's design system MUIv5 roll out 😄 🙏 UPDATE: Created a separate issue for SEO! |
Duplicates
Latest version
Current behavior 😯
After upgrading to MUI5, the autocomplete options custom styles are loaded after the MUI styles which makes me use !important to override the styles.
Expected behavior 🤔
My styles should be loaded first like in other components in order to avoid the use of !important.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: