Skip to content

Commit

Permalink
Remove autofocus on theme switch when page is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-deramond authored and mdo committed Jan 8, 2023
1 parent 1e33cfa commit 3990571
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions site/static/docs/5.3/assets/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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', () => {
Expand All @@ -62,7 +65,7 @@
const theme = toggle.getAttribute('data-bs-theme-value')
localStorage.setItem('theme', theme)
setTheme(theme)
showActiveTheme(theme)
showActiveTheme(theme, true)
})
})
})
Expand Down

0 comments on commit 3990571

Please sign in to comment.