[system] How to correctly merge multiple themes
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
- May be related to https://github.com/mui-org/material-ui/issues/28633, but that one is not specific to combining themes.
Current Behavior 😯
When composing themes (As described under “Theme Composition” https://mui.com/customization/theming/), typography.fontFamily
in the second argument of createTheme
is not applied.
Expected Behavior 🤔
typography.fontFamily
is applied to each typography variant whether or not createTheme
is called with a previous theme as the first argument.
Steps to Reproduce 🕹
https://codesandbox.io/s/mui-5-fontfamily-issue-lwfbf?file=/src/App.js
Steps:
- Create a theme in two steps as described under “Theme Composition” (https://mui.com/customization/theming/)
- In the second call to
createTheme
, settypography.fontFamily
to anything other than the MUI default - See that the custom fontFamily has not been correctly applied
Context 🔦
Workaround is to define typography.fontFamily
in the top level theme. This is a valid work around for me because fontFamily it self does not depend on anything in the previous theme. However, this took me a while to diagnose and worries me that there may be other subtle issues with composing themes.
Your Environment 🌎
`npx @mui/envinfo`
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to combine Windows 7 themes
How to combine Windows 7 themes · 1. Step First of all open the Personalization Control Panel (Right-click on Desktop => Personalize) ·...
Read more >Make Theme Switching Easy with UXPin Merge
Theme switcher cuts down the time to test different themes and change the styles of your design. See how to switch themes quickly...
Read more >Combining themes in Windows 10
Themes are always unique-ish things. Do you mean edit them further? You can do that in the Settings application in the Personalization section....
Read more >Merging Themes
Merging Themes. Sometimes it's useful to split a theme across multiple files, use a preset as the basis for a custom theme, or...
Read more >How to Use Multiple Themes for Pages in WordPress
In this method, we'll use the Multiple Themes plugin to use 2 themes at once on your WordPress site. This method is best...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MikeRawding right, your last solution is the correct one. Just make sure you are not doing this in the component, rather outside of it. I am closing this then.
I came up with this which only merges
ThemeOptions
objects. I still need to generate a trueTheme
at each step so I can access things liketheme.breakpoints.up
(which is not contained inThemeOptions
).https://codesandbox.io/s/mui-5-fontfamily-issue-forked-59t7z?file=/src/App.js