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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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 d9378b9

Comment on lines +251 to +252
'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.',
Copy link
Member

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:

Suggested change
'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`', () => {
Copy link
Member

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`', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('show warning when using `setMode` without configuring `colorSchemeSelector`', () => {
it('warns when using `setMode` without configuring `colorSchemeSelector`', () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants