Skip to content

Commit c14ab16

Browse files
committed
Make theme toggle switch to opposite color when in auto mode
When clicking the toggle in auto mode, it now jumps to the opposite of what's currently displayed (e.g. light if system is dark) instead of always going to light next.
1 parent 8c3e58d commit c14ab16

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/cli/playground/script.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ function applyMode(mode) {
5555
applyMode(currentMode)
5656

5757
document.getElementById("themeBtn").addEventListener("click", () => {
58-
const next = THEME_MODES[(THEME_MODES.indexOf(currentMode) + 1) % THEME_MODES.length]
58+
// From auto, jump to the opposite of what's currently shown
59+
const next = currentMode === "auto"
60+
? (isDark() ? "light" : "dark")
61+
: THEME_MODES[(THEME_MODES.indexOf(currentMode) + 1) % THEME_MODES.length]
5962
applyMode(next)
6063
if (next === "auto") {
6164
localStorage.removeItem(STORAGE_KEY_THEME)

0 commit comments

Comments
 (0)