Skip to content

Commit

Permalink
[website] Fix theme mode toggle state (mui#35216)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored and alexfauquette committed Nov 22, 2022
1 parent 02c4d0c commit 3f2e780
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/pages/_document.js
Expand Up @@ -145,7 +145,7 @@ export default class MyDocument extends Document {
/>
</Head>
<body>
{getMuiInitColorSchemeScript()}
{getMuiInitColorSchemeScript({ defaultMode: 'system' })}
<Main />
<script
// eslint-disable-next-line react/no-danger
Expand Down
2 changes: 1 addition & 1 deletion docs/src/BrandingCssVarsProvider.tsx
Expand Up @@ -51,7 +51,7 @@ const theme = extendTheme({

export default function BrandingCssVarsProvider({ children }: { children: React.ReactNode }) {
return (
<CssVarsProvider theme={theme} disableTransitionOnChange>
<CssVarsProvider theme={theme} defaultMode="system" disableTransitionOnChange>
<NextNProgressBar />
<CssBaseline />
{children}
Expand Down
14 changes: 7 additions & 7 deletions docs/src/components/header/ThemeModeToggle.tsx
Expand Up @@ -11,24 +11,24 @@ function CssVarsModeToggle(props: { onChange: (checked: boolean) => void }) {
React.useEffect(() => {
setMounted(true);
}, []);
const calculatedMode = mode === 'system' ? systemMode : mode;
return (
<Tooltip title={mode === 'dark' ? 'Turn on the light' : 'Turn off the light'}>
<Tooltip title={calculatedMode === 'dark' ? 'Turn on the light' : 'Turn off the light'}>
<IconButton
color="primary"
disableTouchRipple
disabled={!mode}
disabled={!calculatedMode}
onClick={() => {
props.onChange(mode === 'light' || systemMode === 'light');
setMode(mode === 'dark' ? 'light' : 'dark');
props.onChange(calculatedMode === 'light');
setMode(calculatedMode === 'dark' ? 'light' : 'dark');
}}
>
{!mode || !mounted
{!calculatedMode || !mounted
? null
: {
light: <DarkModeOutlined fontSize="small" />,
system: <DarkModeOutlined fontSize="small" />,
dark: <LightModeOutlined fontSize="small" />,
}[mode]}
}[calculatedMode]}
</IconButton>
</Tooltip>
);
Expand Down

0 comments on commit 3f2e780

Please sign in to comment.