feat: make heading links keyboard focusable (#275)

This commit is contained in:
87xie
2024-07-14 17:10:56 +08:00
committed by GitHub
parent 227fcf21e7
commit 7b045a0be8
+8 -4
View File
@@ -157,11 +157,15 @@ const layoutProps = {
let headings = Array.from(document.querySelectorAll("h2, h3, h4, h5, h6"));
for (let heading of headings) {
heading.classList.add("group");
let link = document.createElement("a");
link.innerText = "#";
link.className = "heading-link hidden group-hover:inline-block ml-2";
const link = document.createElement("a");
link.className =
"heading-link ml-2 opacity-0 group-hover:opacity-100 focus:opacity-100";
link.href = "#" + heading.id;
link.ariaHidden = "true";
const span = document.createElement("span");
span.ariaHidden = "true";
span.innerText = "#";
link.appendChild(span);
heading.appendChild(link);
}
}