Skip to content

Commit d0f94d1

Browse files
fix toc to highlight the correct header on click (#5765)
* fix toc to highlight the correct header on click * fix case for when the toc has only a few headings
1 parent 61bf23a commit d0f94d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/components/Layout/useTocHighlight.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import {useState, useRef, useEffect} from 'react';
66

7-
const TOP_OFFSET = 75;
7+
const TOP_OFFSET = 85;
88

99
export function getHeaderAnchors(): HTMLAnchorElement[] {
1010
return Array.prototype.filter.call(
@@ -32,7 +32,7 @@ export function useTocHighlight() {
3232
const scrollPosition = window.scrollY + window.innerHeight;
3333
const headersAnchors = getHeaderAnchors();
3434

35-
if (scrollPosition >= 0 && pageHeight - scrollPosition <= TOP_OFFSET) {
35+
if (scrollPosition >= 0 && pageHeight - scrollPosition <= 0) {
3636
// Scrolled to bottom of page.
3737
setCurrentIndex(headersAnchors.length - 1);
3838
return;

0 commit comments

Comments
 (0)