Skip to content

Commit 3f66af6

Browse files
fix(web): Light theme holds against an OS that prefers dark, and Dark's sidebar sits below the sheet (CL-9659) (#1064)
1 parent 18a08ba commit 3f66af6

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎apps/web/index.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
try {
1313
var t = localStorage.getItem("corbits-theme:last");
1414
var r = document.documentElement;
15-
if (t === "dark" || t === "canvas") r.setAttribute("data-theme", t);
16-
if (t === "dark") r.classList.add("dark");
15+
if (t !== "dark" && t !== "canvas") t = "light";
16+
r.setAttribute("data-theme", t);
17+
r.classList.add(t === "dark" ? "dark" : "light");
1718
r.style.colorScheme = t === "dark" ? "dark" : "light";
1819
} catch (e) {}
1920
</script>

‎apps/web/src/theme-store.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// The theme lives outside React: `data-theme` on <html> is the one switch,
2-
// and this store is its only writer. Light is the absence of the attribute.
2+
// and this store is its only writer. Light is explicit too: react-ui's
3+
// `prefers-color-scheme: dark` block only skips roots carrying `.light`.
34

45
import { reportError } from "@corbits/error-sink";
56
import { useSyncExternalStore } from "react";
@@ -31,10 +32,10 @@ function readStored(key: string): Theme {
3132

3233
function apply(theme: Theme) {
3334
const root = document.documentElement;
34-
if (theme === "light") root.removeAttribute("data-theme");
35-
else root.setAttribute("data-theme", theme);
36-
// react-ui's `dark:` variant keys off the class.
35+
root.setAttribute("data-theme", theme);
36+
// react-ui's `dark:` variant keys off `.dark`; its OS-dark block excludes `.light`.
3737
root.classList.toggle("dark", theme === "dark");
38+
root.classList.toggle("light", theme !== "dark");
3839
root.style.colorScheme = theme === "dark" ? "dark" : "light";
3940
}
4041

0 commit comments

Comments
 (0)