mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2026-11-22 12:39:04 +00:00
fix(footer): move focus to anchor target so keyboard navigation continues from there
This commit is contained in:
1 file changed
+9
-2
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user