Skip to content

fix(docs): light API Reference at the bottom of every component page - #158

Merged
hunterbecton merged 2 commits into
mainfrom
hunter/sha-131-toc-api-reference
Sep 8, 2026
Merged

fix(docs): light API Reference at the bottom of every component page#158
hunterbecton merged 2 commits into
mainfrom
hunter/sha-131-toc-api-reference

Conversation

@hunterbecton

Copy link
Copy Markdown
Contributor

Why

Scrolling to the bottom of a component page sometimes left Usage lit in the table of contents instead of API Reference (SHA-131). It looked intermittent because it depends on window height, not timing.

What changes

The bottom rule picks the last section

useCurrentSection treated the first section title still on screen as current once the page could scroll no further. On a short page in a tall window, Usage's title is still visible at the bottom, so Usage won. Measured with a Playwright probe against every component page, 7 of 15 missed at 1100px tall and 11 of 15 at 1329px. All 15 passed at 800px, which is why it came and went. The rule now lights the last section at the bottom of a page that scrolls. A page that fits its window has no bottom to reach and keeps the reading-line behavior, so it still lights the component on load.

The rule is a pure function with tests

The three rules move out of the hook into current-section.ts, a function over the measured tops and scroll geometry, so they run in the docs Vitest with no DOM. Seven cases cover the Grain measurement that reproduced the bug, the fits-the-window guard, the fractional-scroll tolerance, and the chosen-section hold. The hook is now a measurement loop that reads the DOM once a frame.

The hold on a section chosen from the menu stays as designed. After this fix it pins a non-last row at the bottom only when the jump itself landed there, and the hook comment says why releasing it on the next wheel nudge would be worse.

The active rule grows to 24px

Resting rules are 18px and the current one is 24px, eased at the 100ms step alongside the existing color change. Width rides a duration token and color a fade token, so Reduce Motion snaps the width and keeps the fade. Animating width runs layout, the same trade the props table's panel makes on height, and docs/development/animation.md records the exception beside that one.

The table of contents' bottom-of-page rule picked the first section
title still on screen. In a tall window on a short page, Usage's title
is still visible at the bottom, so Usage stayed lit and API Reference
never did. Measured at 1329px tall, 11 of 15 component pages missed.

Once a page that scrolls can scroll no further, the last section is now
current. The rule moves out of the hook into current-section.ts as a
pure function over the measurements, with tests in plain Node. The hook
only reads the DOM once a frame and hands the numbers over.

The chosen-section hold from the menu stays as designed and the hook
comment says why: after this fix it can only pin a non-last row at the
bottom when a menu jump landed there.
Resting rules draw at 18px and the current section's at 24px, so the
current section reads by shape as well as by color. Both changes ease at
the 100ms step, the width on a duration token and the color on a fade
token, so Reduce Motion snaps the width and keeps the fade.

Animating width runs layout, which the site otherwise avoids. The stack
is three 2px rules in a fixed-width column that nothing else depends on,
the same trade the props table's panel makes on height. animation.md
records the exception beside that one.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 6373477.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: e1b48a84-0e14-49f9-b733-998e32350d81

📥 Commits

Reviewing files that changed from the base of the PR and between 56fa628 and 6373477.

📒 Files selected for processing (5)
  • apps/docs/src/components/page-toc/current-section.test.ts
  • apps/docs/src/components/page-toc/current-section.ts
  • apps/docs/src/components/page-toc/page-toc.module.css
  • apps/docs/src/components/page-toc/page-toc.tsx
  • docs/development/animation.md

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Improved the floating table of contents to select and retain the appropriate active section while scrolling.
    • Added a smooth animation that expands the active section indicator and changes its color.
  • Documentation

    • Documented the floating table of contents animation behavior.

Walkthrough

The change extracts page table of contents section selection into a tested helper. It adds bottom-of-page and chosen-section handling, integrates the helper into the hook, and animates active line width with updated documentation.

Changes

Page table of contents

Layer / File(s) Summary
Section selection and integration
apps/docs/src/components/page-toc/current-section.ts, apps/docs/src/components/page-toc/current-section.test.ts, apps/docs/src/components/page-toc/page-toc.tsx
The new pickCurrentSection helper selects sections by chosen-section visibility, scroll position, and reading-line position. Tests cover these rules. useCurrentSection now uses the helper and clears the chosen section when it is no longer held.
Active line animation
apps/docs/src/components/page-toc/page-toc.module.css, docs/development/animation.md
TOC lines transition width and background color. Active lines expand from 18px to 24px. The animation documentation describes the implementation.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 63734

The page table of contents now highlights the final section at the end of scrollable pages and adds an animated active rule. The behavior is covered by focused tests and is ready to merge.

Sequence Diagram(s)

sequenceDiagram
  participant useCurrentSection
  participant pickCurrentSection
  participant chosenRef
  participant PageTocLine
  useCurrentSection->>pickCurrentSection: pass section and scroll measurements
  pickCurrentSection->>chosenRef: evaluate chosen section visibility
  pickCurrentSection-->>useCurrentSection: return index and held
  useCurrentSection->>chosenRef: clear chosen index when held is false
  useCurrentSection->>PageTocLine: update active section
  PageTocLine->>PageTocLine: transition width and background color
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bottom-of-page highlighting bug, the pure-function refactor, tests, and active-rule animation changes.
Title check ✅ Passed The title clearly identifies the documentation table-of-contents fix and the affected bottom-of-page behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

@hunterbecton
hunterbecton merged commit c17e25a into main Sep 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant