From f7739173327f2f4600a7b63fad19f3a4c6ec2f52 Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 10 Sep 2025 21:26:21 +0200 Subject: [PATCH 1/2] fix(theme): skip link jumps to aside instead main content heading/anchor --- src/client/theme-default/components/VPSkipLink.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/theme-default/components/VPSkipLink.vue b/src/client/theme-default/components/VPSkipLink.vue index ad56622d..10c987e4 100644 --- a/src/client/theme-default/components/VPSkipLink.vue +++ b/src/client/theme-default/components/VPSkipLink.vue @@ -10,10 +10,12 @@ const backToTop = ref() watch(() => route.path, () => backToTop.value.focus()) function focusOnTargetAnchor({ target }: Event) { - const el = document.getElementById( + const targetEl = document.getElementById( decodeURIComponent((target as HTMLAnchorElement).hash).slice(1) ) + const el = targetEl?.querySelector('main h1[id][tabindex="-1"]') ?? targetEl + if (el) { const removeTabIndex = () => { el.removeAttribute('tabindex') From 3f2009071a5827b4d5327fea8ed896c8c5a990b7 Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 10 Sep 2025 21:45:23 +0200 Subject: [PATCH 2/2] chore: use fixed position for the skip link --- .../theme-default/components/VPSkipLink.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/theme-default/components/VPSkipLink.vue b/src/client/theme-default/components/VPSkipLink.vue index 10c987e4..1ca0c457 100644 --- a/src/client/theme-default/components/VPSkipLink.vue +++ b/src/client/theme-default/components/VPSkipLink.vue @@ -17,13 +17,15 @@ function focusOnTargetAnchor({ target }: Event) { const el = targetEl?.querySelector('main h1[id][tabindex="-1"]') ?? targetEl if (el) { - const removeTabIndex = () => { - el.removeAttribute('tabindex') - el.removeEventListener('blur', removeTabIndex) - } + if (!el.hasAttribute('tabindex')) { + const removeTabIndex = () => { + el.removeAttribute('tabindex') + el.removeEventListener('blur', removeTabIndex) + } - el.setAttribute('tabindex', '-1') - el.addEventListener('blur', removeTabIndex) + el.setAttribute('tabindex', '-1') + el.addEventListener('blur', removeTabIndex) + } el.focus() window.scrollTo(0, 0) } @@ -43,6 +45,7 @@ function focusOnTargetAnchor({ target }: Event) {