restore tabindex if unable to focus even after modifying tabindex

pull/4943/head
Divyansh Singh 1 week ago
parent fa4780d6cc
commit f320044aa9

@ -290,15 +290,16 @@ export function scrollTo(hash: string, smooth = false, scrollPosition = 0) {
// target is not focusable, make it temporarily focusable // target is not focusable, make it temporarily focusable
const tabindex = target.getAttribute('tabindex') const tabindex = target.getAttribute('tabindex')
target.setAttribute('tabindex', '-1') target.setAttribute('tabindex', '-1')
target.addEventListener(
'blur', const restoreTabindex = () => {
() => { if (tabindex == null) target.removeAttribute('tabindex')
if (tabindex == null) target.removeAttribute('tabindex') else target.setAttribute('tabindex', tabindex)
else target.setAttribute('tabindex', tabindex) target.removeEventListener('blur', restoreTabindex)
}, }
{ once: true } target.addEventListener('blur', restoreTabindex)
)
target.focus({ preventScroll: true }) target.focus({ preventScroll: true })
if (document.activeElement !== target) restoreTabindex()
} }
requestAnimationFrame(scrollToTarget) requestAnimationFrame(scrollToTarget)

Loading…
Cancel
Save