@@ -55,7 +55,7 @@ const maxLevel = siteConfig.toc.depth;
5555 }]} >{ removeTailingHash (heading .text )} </div >
5656 </a >
5757 )}
58- <div id = " active-indicator" class :list = { [{' hidden' : headings .length == 0 }, " -z-10 absolute bg-[var(--toc-btn-hover)] left-0 right-0 rounded-xl transition-all " +
58+ <div id = " active-indicator" style = " opacity: 0 " class :list = { [{' hidden' : headings .length == 0 }, " -z-10 absolute bg-[var(--toc-btn-hover)] left-0 right-0 rounded-xl transition-all " +
5959 " group-hover:bg-transparent border-2 border-[var(--toc-btn-hover)] group-hover:border-[var(--toc-btn-active)] border-dashed" ]} ></div >
6060</table-of-contents >}
6161
@@ -97,7 +97,7 @@ class TableOfContents extends HTMLElement {
9797
9898 toggleActiveHeading = () => {
9999 let i = this.active.length - 1;
100- let min = this.active.length - 1, max = 0 ;
100+ let min = this.active.length - 1, max = -1 ;
101101 while (i >= 0 && !this.active[i]) {
102102 this.tocEntries[i].classList.remove(this.visibleClass);
103103 i--;
@@ -112,11 +112,15 @@ class TableOfContents extends HTMLElement {
112112 this.tocEntries[i].classList.remove(this.visibleClass);
113113 i--;
114114 }
115- let parentOffset = this.tocEl?.getBoundingClientRect().top || 0;
116- let scrollOffset = this.tocEl?.scrollTop || 0;
117- let top = this.tocEntries[min].getBoundingClientRect().top - parentOffset + scrollOffset;
118- let bottom = this.tocEntries[max].getBoundingClientRect().bottom - parentOffset + scrollOffset;
119- this.activeIndicator?.setAttribute("style", `top: ${top}px; height: ${bottom - top}px`);
115+ if (min > max) {
116+ this.activeIndicator?.setAttribute("style", `opacity: 0`);
117+ } else {
118+ let parentOffset = this.tocEl?.getBoundingClientRect().top || 0;
119+ let scrollOffset = this.tocEl?.scrollTop || 0;
120+ let top = this.tocEntries[min].getBoundingClientRect().top - parentOffset + scrollOffset;
121+ let bottom = this.tocEntries[max].getBoundingClientRect().bottom - parentOffset + scrollOffset;
122+ this.activeIndicator?.setAttribute("style", `top: ${top}px; height: ${bottom - top}px`);
123+ }
120124 };
121125
122126 scrollToActiveHeading = () => {
0 commit comments