diff --git a/layouts/_partials/footer.html b/layouts/_partials/footer.html
index 3fa4f327..218bf575 100644
--- a/layouts/_partials/footer.html
+++ b/layouts/_partials/footer.html
@@ -64,13 +64,20 @@
anchor.addEventListener("click", function (e) {
e.preventDefault();
var id = this.getAttribute("href").substr(1);
+ const target = document.querySelector(`[id='${decodeURIComponent(id)}']`);
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
- document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
+ target.scrollIntoView({
behavior: "smooth"
});
} else {
- document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView();
+ target.scrollIntoView();
}
+ // Move keyboard focus to the target like native anchor navigation,
+ // so the next Tab continues from there instead of from this link
+ if (target.tabIndex < 0 && !target.hasAttribute("tabindex")) {
+ target.setAttribute("tabindex", "-1");
+ }
+ target.focus({ preventScroll: true });
if (id === "top") {
history.replaceState(null, null, " ");
} else {