Skip to content

Commit 11218f2

Browse files
authored
Merge pull request #33 from techniq/themestore-system-dark-mode
fix(themeStore): Only manage system dark mode (`<html class="dark">`) if there are any dark themes defined
2 parents a2eb6eb + f2a3749 commit 11218f2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.changeset/fresh-worlds-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/svelte-stores': patch
3+
---
4+
5+
fix(themeStore): Only manage system dark mode (`<html class="dark">`) if there are any dark themes defined

packages/svelte-stores/src/lib/themeStore.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ export function createThemeStore(options: ThemeStoreOptions): ThemeStore {
4848
let darkMatcher = window.matchMedia('(prefers-color-scheme: dark)');
4949

5050
function resolveSystemTheme({ matches }: { matches: boolean }) {
51-
if (matches && options.dark.length) {
52-
document.documentElement.classList.add('dark');
53-
} else {
54-
document.documentElement.classList.remove('dark');
51+
// Only manage dark mode (`<html class="dark">`) if there are any dark themes defined
52+
if (options.dark.length) {
53+
if (matches) {
54+
document.documentElement.classList.add('dark');
55+
} else {
56+
document.documentElement.classList.remove('dark');
57+
}
5558
}
5659

5760
store.set(new CurrentTheme(null, matches));

0 commit comments

Comments
 (0)