Skip to content

Commit 0950bfa

Browse files
committed
[Site] Fix minor bug where theme didn't change on first click
1 parent 2fd1737 commit 0950bfa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ux.symfony.com/assets/controllers/theme-switcher-controller.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { Controller } from '@hotwired/stimulus';
22

33
export default class extends Controller {
44
switch() {
5-
const theme = localStorage.getItem('user-theme') === 'dark' ? 'light' : 'dark';
5+
let currentTheme = localStorage.getItem('user-theme');
6+
if (!currentTheme) {
7+
currentTheme = document.documentElement.getAttribute('data-bs-theme');
8+
}
9+
10+
const theme = currentTheme === 'dark' ? 'light' : 'dark';
611
localStorage.setItem('user-theme', theme);
712
document.documentElement.setAttribute('data-bs-theme', theme);
813
}

0 commit comments

Comments
 (0)