From f16560c1ee212041def4211b0c4954191156e20b Mon Sep 17 00:00:00 2001 From: Brett Jephson Date: Wed, 25 Sep 2024 08:52:44 +0100 Subject: [PATCH] Scroll offset (#2484) --- .changeset/pink-feet-bake.md | 5 +++++ .../gitbook/src/components/TableOfContents/TOCScroller.tsx | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/pink-feet-bake.md 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 24382fbf3..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 || tocItemTop > containerBottom; + return ( + tocItemTop < containerTop + TOC_ITEM_OFFSET || + tocItemTop > containerBottom - TOC_ITEM_OFFSET + ); }