Skip to content

fix(#3726): highlight last TOC heading when scrolled to bottom#3727

Open
twjeffery wants to merge 1 commit intodevfrom
claude/fix-toc-bottom-scroll-KKTU5
Open

fix(#3726): highlight last TOC heading when scrolled to bottom#3727
twjeffery wants to merge 1 commit intodevfrom
claude/fix-toc-bottom-scroll-KKTU5

Conversation

@twjeffery
Copy link
Copy Markdown
Collaborator

@twjeffery twjeffery commented Mar 31, 2026

Summary

  • Fixes the sticky TOC highlighting the wrong section for short sections near the bottom of the page (e.g. "Get started" on the workspace page)
  • Adds a bottom-of-page check in handleScroll: when window.innerHeight + window.scrollY >= document.body.scrollHeight - 10, the last visible heading is set as active instead of relying on the 120px threshold
Screen.Recording.2026-03-31.at.3.07.21.PM.mov

Closes #3726

Test plan

  • Navigate to a docs page with a short final section (e.g. workspace example page)
  • Scroll to the very bottom of the page — the last TOC item should be highlighted
  • Click the last TOC item — it should become active
  • Scroll back up — TOC highlighting should still work normally for all other sections

https://claude.ai/code/session_01Rcc9hcmnjnE8vdXhiz7VMM

When the page is scrolled to the bottom, short sections near the end
never reach the 120px threshold, so the TOC highlights the wrong item.
Detect bottom-of-page and activate the last visible heading instead.

https://claude.ai/code/session_01Rcc9hcmnjnE8vdXhiz7VMM
@twjeffery twjeffery changed the title Fix TableOfContents active heading when scrolled to bottom fix(#3726): highlight last TOC heading when scrolled to bottom Mar 31, 2026
@Spark450 Spark450 added the P3 Priority 3 (nice to have): Valuable, but safe to release after launch. label Mar 31, 2026
@twjeffery twjeffery requested a review from Spark450 March 31, 2026 21:09
Copy link
Copy Markdown
Collaborator

@Spark450 Spark450 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is certainly working better but it looks like the selection "bounces" a bit then settles.
https://jam.dev/c/08f2e673-e30e-4d7d-a609-a1a81e62637a

@twjeffery
Copy link
Copy Markdown
Collaborator Author

I think it is certainly working better but it looks like the selection "bounces" a bit then settles. jam.dev/c/08f2e673-e30e-4d7d-a609-a1a81e62637a

I think that's expected for what it's fixing and doing. This is a fix to make it change (override what's set from the scroll position) to the last item if scroll is at the bottom. It's kind of like, it follows the heading based on the scroll position, and then if the scroll is at the bottom, then set it to bottom as active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Priority 3 (nice to have): Valuable, but safe to release after launch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: sticky inline TOC highlights wrong section for short sections near bottom of page

3 participants