-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[material-ui] How to properly merge themes that are using styleOverrides functions? #42427
Comments
You need to merge the styleOverrides defined in both themes. You can specify them as an array of functions and have a On the other hand, we could implement this functionality internally in the @mui packages. cc @siriwatknp, @brijeshb42 what are your thoughts? We haven't done it so far, because it could be expensive to do this always and it seems like it is not that common scenario. Also, our internal deepmerge function doesn't consider arrays. |
Thanks @mnajdova, that's exactly what I wanted! Granted this might not be a super common use case I understand if this is something you won't add internally. But if you do It would be greatly appreciated! Thanks again! |
I also ran into this issue. Would be nice to have a first party solution that doesn't require passing arrays to styleOverride slots, but @mnajdova 's solution works in the meantime! |
It appears that not all Mui components support this array syntax, e.g. https://stackblitz.com/edit/react-nyzyvq?file=Demo.tsx Update: It looks like this issue was fixed in Mui 6.2.1 likely as a result of #44752 https://stackblitz.com/edit/react-nyzyvq-p48plcw9?file=Demo.tsx |
I did get something working, but am not keen on "owning" so much merging complexity. I too would love some more guidance. FWIW, I maintain an internal component library, built on top of Mui. The following is a somewhat simplified example of my custom createTheme function. |
Steps to reproduce
Link to live example
Steps:
({ theme }) => (
function when overriding a components root styles.experimental_extendTheme
Current behavior
Styles don't get merged, the
textTransform
gets dropped and logging out the theme we can see this errorChanging the styleOverrides from
to
merges the themes successfully.
Expected behavior
I might be going about this the wrong way and would appreciate any guidance in the matter.
Context
I'd like to have one base theme with some defaults which I'm then going to override parts of with various themes. I'd like to be able to use the theming functions to get access to things like
theme.spacing()
etc.Your environment
npx @mui/envinfo
Search keywords: merge, themes
The text was updated successfully, but these errors were encountered: