mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-26 23:54:23 +01:00
Remove autofocus on theme switch when page is loaded
This commit is contained in:
parent
1e33cfa272
commit
39905711fa
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
setTheme(getPreferredTheme())
|
setTheme(getPreferredTheme())
|
||||||
|
|
||||||
const showActiveTheme = theme => {
|
const showActiveTheme = (theme, focus = false) => {
|
||||||
const themeSwitcher = document.querySelector('#bd-theme')
|
const themeSwitcher = document.querySelector('#bd-theme')
|
||||||
const themeSwitcherText = document.querySelector('#bd-theme-text')
|
const themeSwitcherText = document.querySelector('#bd-theme-text')
|
||||||
const activeThemeIcon = document.querySelector('.theme-icon-active use')
|
const activeThemeIcon = document.querySelector('.theme-icon-active use')
|
||||||
@ -44,8 +44,11 @@
|
|||||||
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
|
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
|
||||||
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
|
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
|
||||||
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
|
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
|
||||||
|
|
||||||
|
if (focus) {
|
||||||
themeSwitcher.focus()
|
themeSwitcher.focus()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||||
if (storedTheme !== 'light' || storedTheme !== 'dark') {
|
if (storedTheme !== 'light' || storedTheme !== 'dark') {
|
||||||
@ -62,7 +65,7 @@
|
|||||||
const theme = toggle.getAttribute('data-bs-theme-value')
|
const theme = toggle.getAttribute('data-bs-theme-value')
|
||||||
localStorage.setItem('theme', theme)
|
localStorage.setItem('theme', theme)
|
||||||
setTheme(theme)
|
setTheme(theme)
|
||||||
showActiveTheme(theme)
|
showActiveTheme(theme, true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user