From 39905711fab711ac6f99f8a987931bdee9376b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20D=C3=A9ramond?= Date: Sun, 8 Jan 2023 15:58:59 +0100 Subject: [PATCH] Remove autofocus on theme switch when page is loaded --- site/static/docs/5.3/assets/js/color-modes.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/site/static/docs/5.3/assets/js/color-modes.js b/site/static/docs/5.3/assets/js/color-modes.js index fdd3303dc6..68717f82d6 100644 --- a/site/static/docs/5.3/assets/js/color-modes.js +++ b/site/static/docs/5.3/assets/js/color-modes.js @@ -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') @@ -44,7 +44,10 @@ 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) }) }) })