pull/4940/merge
Joaquín Sánchez 1 week ago committed by GitHub
commit a529513cde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,11 +10,14 @@ const backToTop = ref()
watch(() => route.path, () => backToTop.value.focus()) watch(() => route.path, () => backToTop.value.focus())
function focusOnTargetAnchor({ target }: Event) { function focusOnTargetAnchor({ target }: Event) {
const el = document.getElementById( const targetEl = document.getElementById(
decodeURIComponent((target as HTMLAnchorElement).hash).slice(1) decodeURIComponent((target as HTMLAnchorElement).hash).slice(1)
) )
const el = targetEl?.querySelector<HTMLAnchorElement>('main h1[id][tabindex="-1"]') ?? targetEl
if (el) { if (el) {
if (!el.hasAttribute('tabindex')) {
const removeTabIndex = () => { const removeTabIndex = () => {
el.removeAttribute('tabindex') el.removeAttribute('tabindex')
el.removeEventListener('blur', removeTabIndex) el.removeEventListener('blur', removeTabIndex)
@ -22,6 +25,7 @@ function focusOnTargetAnchor({ target }: Event) {
el.setAttribute('tabindex', '-1') el.setAttribute('tabindex', '-1')
el.addEventListener('blur', removeTabIndex) el.addEventListener('blur', removeTabIndex)
}
el.focus() el.focus()
window.scrollTo(0, 0) window.scrollTo(0, 0)
} }
@ -41,6 +45,7 @@ function focusOnTargetAnchor({ target }: Event) {
<style scoped> <style scoped>
.VPSkipLink { .VPSkipLink {
position: fixed;
top: 8px; top: 8px;
left: 8px; left: 8px;
padding: 8px 16px; padding: 8px 16px;

Loading…
Cancel
Save