Skip to content

Commit

Permalink
theming: fix the theming to set the correct dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiramtilakiiit committed Jan 13, 2025
1 parent b85ad73 commit 21dfc5b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/ThemeRegistry/ThemeRegistry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default function ThemeRegistry({ children, nonce }) {
const theme = createTheme(themeOptions);
theme.components = componentsOverride(theme);

// Update the global background color
React.useEffect(() => {
const backgroundColor = prefersDarkMode.isDark
? palette.dark.background.default
: palette.light.background.default;

document.body.style.backgroundColor = backgroundColor;

return () => {
// Optional cleanup
document.body.style.backgroundColor = "";
};
}, [prefersDarkMode]);

return (
<NextAppDirEmotionCacheProvider options={{ key: "mui", nonce: nonce }}>
<ThemeProvider theme={theme}>
Expand Down

0 comments on commit 21dfc5b

Please sign in to comment.