From 32aeb9b8b6b0fd454fba8fade7308f933ea89581 Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Wed, 28 Aug 2024 13:26:48 +0700 Subject: [PATCH] fix no colorSchemeSelector --- packages/mui-material/src/styles/createTheme.test.js | 11 +++++++++++ packages/mui-material/src/styles/createTheme.ts | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/packages/mui-material/src/styles/createTheme.test.js b/packages/mui-material/src/styles/createTheme.test.js index 926a80321b6ef9..9ec0a1a2a776e5 100644 --- a/packages/mui-material/src/styles/createTheme.test.js +++ b/packages/mui-material/src/styles/createTheme.test.js @@ -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, diff --git a/packages/mui-material/src/styles/createTheme.ts b/packages/mui-material/src/styles/createTheme.ts index 5bf0b5ed8072ba..dd2b26c6fbad65 100644 --- a/packages/mui-material/src/styles/createTheme.ts +++ b/packages/mui-material/src/styles/createTheme.ts @@ -96,6 +96,10 @@ export default function createTheme( return theme; } + if (!palette && !('light' in colorSchemesInput) && defaultColorSchemeInput === 'light') { + colorSchemesInput.light = true; + } + return createThemeWithVars( { ...rest,