]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Remove autofocus on theme switch when page is loaded
authorJulien Déramond <juderamond@gmail.com>
Sun, 8 Jan 2023 14:58:59 +0000 (15:58 +0100)
committerMark Otto <otto@github.com>
Sun, 8 Jan 2023 23:39:31 +0000 (15:39 -0800)
site/static/docs/5.3/assets/js/color-modes.js

index fdd3303dc6492349b4f56814926229f53cecae0b..68717f82d6e9cbe434ab46adba8d0fe77f75e2c6 100644 (file)
@@ -27,7 +27,7 @@
 
   setTheme(getPreferredTheme())
 
-  const showActiveTheme = theme => {
+  const showActiveTheme = (theme, focus = false) => {
     const themeSwitcher = document.querySelector('#bd-theme')
     const themeSwitcherText = document.querySelector('#bd-theme-text')
     const activeThemeIcon = document.querySelector('.theme-icon-active use')
     activeThemeIcon.setAttribute('href', svgOfActiveBtn)
     const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
     themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
-    themeSwitcher.focus()
+
+    if (focus) {
+      themeSwitcher.focus()
+    }
   }
 
   window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
@@ -62,7 +65,7 @@
           const theme = toggle.getAttribute('data-bs-theme-value')
           localStorage.setItem('theme', theme)
           setTheme(theme)
-          showActiveTheme(theme)
+          showActiveTheme(theme, true)
         })
       })
   })