-
-
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
Unchanged colours on theme switching (dark/light) #18831
Comments
👋 Thanks for using Material-UI! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://material-ui.com/getting-started/support/. Thanks! If you have a question on StackOverflow, you are welcome to link to it here, it might help others. |
It's somewhat related to #18776. |
Yes, it is indeed kind of related, I believe that an effort should be made to ensure that the colour property of all components get updated on theme switching. In the case that I documented in this ticket, the bug affects The fix is quite simple, just switch the colour property of non-surface objects to (primary/secondary).light on a dark theme and (primary/secondary).dark on a light theme this is what I have been programmatically doing on the previous website I designed with Material UI and having this issue fixed on the library level would be awesome! |
@aress31 Without a reproduction, I'm not sure to understand the problem you are facing. As far as I know, it's a documentation/teaching issue. |
Alright, let me try to rephrase the bug/issue. The palette: {
type: isDarkMode ? 'dark' : 'light',
primary: red,
secondary: grey,
// Used by `getContrastText()` to maximize the contrast between the background and
// the text.
contrastThreshold: 4,
// Used to shift a color's luminance by approximately
// two indexes within its tonal palette.
// E.g., shift from Red 500 to Red 300 or Red 700.
tonalOffset: 0.4,
background: {
default: isDarkMode ? '#121212' : '#FFFFFF',
},
}, The colour of the |
It wasn't designed to behave this way, you need to change the colors. |
Ok @oliviertassinari understood, but maybe this should be considered as it helps boosting up the contrast between foreground and background, or at least maybe the option to have the colour palette behave this way should be implemented? |
@aress31 I believe it's the responsibility of the developers when providing a custom palette to make sure the contrast is good enough. |
@oliviertassinari I totally agree but the problem here is that only the |
@oliviertassinari, I think that my issue was not entirely understood. Material Design states that on a dark theme, unsaturated colours should be used in order to improve the contrast with the background and limit eye strains as opposed to a light theme where saturated colours are used. Right now I hope that I made my ticket clearer. 😁 |
@aress31 I faced the same issue after is stopped using the jss provider. In short, rather than passing the theme you generated once for ThemeProvider, you have to generate it each time you change it so it affects all styles. In code: const themeA =createMuiTheme(...); --> const geThemeA =()=>createMuiTheme(...);
const themeB =createMuiTheme(...); --> const getThemeB =()=>createMuiTheme(...);
...
switchTheme=(...)...setState{theme:a?themeA:themeB}; --> switchTheme(...)...setState{theme:a?geThemeA():geThemeB()};
...
<ThemeProvider theme={theme}> |
This works for us. The |
Thanks this helps!! 🚀 |
I wish there was a way in the Box component to use declarative colors and let the framework pick the right one based on the current theme mode. For example:
if the mode is light, then it uses I also don't full understand why As of today I keep having to change my markup with boilerplate repetitive code like this:
|
The palette colours (primary and secondary colours) remain unchanged over dynamically switching from dark/light themes. This is behaviour can clearly be observed with
<Typography>
objects, this forces developers to programmatically check if the theme is in dark or light mode and to accordingly adapt the colours adding a lot of overhead.Current Behavior 😯
Expected Behavior 🤔
I defined my primary colour to
red
(import red from '@material-ui/core/colors/red';
). On a dark mode in the colour code is#f44336
and on a light mode the colour code is#f44336
. See the following screenshots:Dark mode:
Light mode:
The theme should automatically switch colours according to the selected mode, in dark mode a lighter variant (e.g. red[300]) of colours should be picked whereas in light mode darker variant of the palette colour should be picked (e.g. red[700]) to increase the contrast and improve the overall design.
Steps to Reproduce 🕹
Steps:
red
and secondary colour toyellow
.<Typography>
component with thecolor:'primary'
propriety set.Context 🔦
I am trying to maximise the contrast of my text elements and improve the overall aesthetic of my website.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: