fix(footer): move focus to anchor target so keyboard navigation continues from there

This commit is contained in:
Aditya Telange committed 2026-10-25 11:53:51 +05:30
1 parent 28cbd3c581
commit 118119693d
1 file changed
+9 -2
+9 -2
View File
@@ -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 {