Skip to content
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

Merged
merged 8 commits into from
Nov 15, 2024

Conversation

siriwatknp
Copy link
Member

From #43533 (comment)

Currently with CSS theme variables enabled, calling setMode has no effect if colorSchemeSelector 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 configuring colorSchemeSelector.

@siriwatknp siriwatknp added package: system Specific to @mui/system enhancement This is not a bug, nor a new feature labels Sep 16, 2024
@siriwatknp siriwatknp changed the title [system] Warn/use color scheme [system] Warn when calling setMode without configuring colorSchemeSelector Sep 16, 2024
@mui-bot
Copy link

mui-bot commented Sep 16, 2024

Netlify deploy preview

https://deploy-preview-43783--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against c26a0bc

@siriwatknp
Copy link
Member Author

siriwatknp commented Nov 11, 2024

@aarongarciah Sorry for the delay, I applied your suggesion. Could you do another review?

@siriwatknp siriwatknp merged commit 016acab into mui:master Nov 15, 2024
19 checks passed
[
'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',
Copy link
Member

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

Suggested change
'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).',
Copy link
Member

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?
Suggested change
'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.

@oliviertassinari oliviertassinari added the dx Related to developers' experience label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Related to developers' experience enhancement This is not a bug, nor a new feature package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants