Skip to content

Commit

Permalink
[material-ui] Attach default light color scheme when enabling CSS the…
Browse files Browse the repository at this point in the history
…me variables (#43493)
  • Loading branch information
siriwatknp authored Aug 29, 2024
1 parent 029eb3b commit 975ecbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 975ecbb

Please sign in to comment.