-
-
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
Conversation
setMode
without configuring colorSchemeSelector
Netlify deploy previewhttps://deploy-preview-43783--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
d9378b9
to
3bf744e
Compare
…l-ui into warn/use-color-scheme
@aarongarciah Sorry for the delay, I applied your suggesion. Could you do another review? |
[ | ||
'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.', | ||
'To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually', |
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.
How about we enforce all of those links to be permalink? mui/mui-public#222
'To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually', | |
'To learn more, visit https://mui.com/r/set-mode-media', | |
Especially a hash link, it seems too brittle.
if (theme.colorSchemeSelector === 'media') { | ||
console.error( | ||
[ | ||
'MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', |
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.
- () To match with how we reference functions in the docs?
- if -> when. If could create doubt about either this is true or not in the case the warning triggers?
'MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', | |
'MUI: The `setMode()` function has no effect when `colorSchemeSelector` is `media` (`media` is the default value).', |
Rule of error messages: https://www.notion.so/mui-org/Technical-writing-guidance-7e55b517ac2e489a9ddb6d0f6dd765de?pvs=4#85219822c3194b6f8a49ee08ea82b90a.
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
.