-
-
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
[system] Warn when calling setMode
without configuring colorSchemeSelector
#43783
base: master
Are you sure you want to change the base?
Conversation
setMode
without configuring colorSchemeSelector
Netlify deploy previewhttps://deploy-preview-43783--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
'MUI: The `setMode` function has no effect if `colorSchemeSelector` is not configured.', | ||
'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is not configured" might be confusing, because one can explicitly set colorSchemeSelector: 'media'
in the theme. Maybe we can reword it:
'MUI: The `setMode` function has no effect if `colorSchemeSelector` is not configured.', | |
'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', | |
'MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', | |
'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', |
@@ -360,4 +367,24 @@ describe('[Material UI] ThemeProviderWithVars', () => { | |||
borderBottomRightRadius: '16px', | |||
}); | |||
}); | |||
|
|||
it('show warning when using `setMode` without configuring `colorSchemeSelector`', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's worth it, but we could also test when explicitly setting colorSchemeSelector: 'media'
.
@@ -360,4 +367,24 @@ describe('[Material UI] ThemeProviderWithVars', () => { | |||
borderBottomRightRadius: '16px', | |||
}); | |||
}); | |||
|
|||
it('show warning when using `setMode` without configuring `colorSchemeSelector`', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('show warning when using `setMode` without configuring `colorSchemeSelector`', () => { | |
it('warns when using `setMode` without configuring `colorSchemeSelector`', () => { |
From #43533 (comment)
Currently with CSS theme variables enabled, calling
setMode
has no effect ifcolorSchemeSelector
is not configured. Technically, this is correct because the default method is@media (prefers-color-scheme)
, so user cannot toggle mode manually.However, from the DX perspective, it's confusion of why it does not work. This PR added a warning if calling
setMode
without configuringcolorSchemeSelector
.