We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2fd1737 commit 0950bfaCopy full SHA for 0950bfa
ux.symfony.com/assets/controllers/theme-switcher-controller.js
@@ -2,7 +2,12 @@ import { Controller } from '@hotwired/stimulus';
2
3
export default class extends Controller {
4
switch() {
5
- const theme = localStorage.getItem('user-theme') === 'dark' ? 'light' : 'dark';
+ 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';
11
localStorage.setItem('user-theme', theme);
12
document.documentElement.setAttribute('data-bs-theme', theme);
13
}
0 commit comments