diff --git a/.changeset/pink-feet-bake.md b/.changeset/pink-feet-bake.md new file mode 100644 index 000000000..ca03136d6 --- /dev/null +++ b/.changeset/pink-feet-bake.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Include offset in calculations of whether scrollable element is in view diff --git a/packages/gitbook/src/components/TableOfContents/TOCScroller.tsx b/packages/gitbook/src/components/TableOfContents/TOCScroller.tsx index 6058e673e..a2457aee4 100644 --- a/packages/gitbook/src/components/TableOfContents/TOCScroller.tsx +++ b/packages/gitbook/src/components/TableOfContents/TOCScroller.tsx @@ -66,5 +66,8 @@ function isOutOfView(tocItem: HTMLElement, tocContainer: HTMLElement) { const tocItemTop = tocItem.offsetTop; const containerTop = tocContainer.scrollTop; const containerBottom = containerTop + tocContainer.clientHeight; - return tocItemTop < containerTop + TOC_ITEM_OFFSET || tocItemTop > containerBottom - TOC_ITEM_OFFSET; + return ( + tocItemTop < containerTop + TOC_ITEM_OFFSET || + tocItemTop > containerBottom - TOC_ITEM_OFFSET + ); }