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

[material-ui] Attach default light color scheme when enabling CSS theme variables #43493

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/mui-material/src/styles/createTheme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ describe('createTheme', () => {
});

describe('CSS variables', () => {
it('should have default light with media selector if no `palette` and colorSchemes.dark is provided ', () => {
const theme = createTheme({
cssVariables: true,
colorSchemes: { dark: true },
});
expect(theme.defaultColorScheme).to.equal('light');
expect(theme.colorSchemeSelector).to.equal('media');
expect(theme.colorSchemes.light).not.to.equal(undefined);
expect(theme.colorSchemes.dark).not.to.equal(undefined);
});

it('should have a light as a default colorScheme if only `palette` is provided', () => {
const theme = createTheme({
cssVariables: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-material/src/styles/createTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export default function createTheme(
return theme;
}

if (!palette && !('light' in colorSchemesInput) && defaultColorSchemeInput === 'light') {
colorSchemesInput.light = true;
}

return createThemeWithVars(
{
...rest,
Expand Down