docs: fix potential null errors (#2324)

This commit is contained in:
Marvin Hagemeister
2024-02-20 01:19:08 +01:00
committed by GitHub
parent f1c17bc67e
commit 46eaef0181
2 changed files with 7 additions and 3 deletions
+6 -2
View File
@@ -17,6 +17,8 @@ function setActiveLink(
`a[href="#${id}"]`,
) as HTMLElement;
if (tocLink === null) return;
tocLink.classList.add("active");
const rect = tocLink
@@ -62,8 +64,10 @@ export function TableOfContents({ headings }: TableOfContentsProps) {
const id = headings[i].id;
const tocLink = container.querySelector(
`a[href="#${id}"]`,
) as HTMLElement;
tocLink.classList.remove("active");
);
if (tocLink !== null) {
tocLink.classList.remove("active");
}
}
let activeIdx = visibleList.indexOf(true);