Skip to content

feat(flame): show reading progress in the mobile toc bar - #472

Merged
gitfromwildan merged 1 commit into
mainfrom
feat/flame-mobile-toc-progress
Nov 5, 2026
Merged

gitfromwildan merged 1 commit into
mainfrom
feat/flame-mobile-toc-progress

Conversation

@gitfromwildan

Copy link
Copy Markdown
Member

Summary

The mobile docs bar now shows reading progress. A small circular indicator sits to the left of the current section's title, inline in the bar's table of contents button.

Behavior

  • Progress is the share of sections reached: the active heading's position among the page's headings. On a page with 9 headings, the 5th section reads 56%.
  • End of page counts as 100%. A short last section never scrolls up to the anchor offset, so it would otherwise never become active and the ring would stop short.
  • Ring: 18px, a faint base-content track and a primary arc. At 0 only the track is drawn, so the round cap shows no dot. The fill animates its stroke-dashoffset, except under prefers-reduced-motion.
  • Accessibility: the ring is aria-hidden. The button's accessible name carries the percentage, for example "Expand table of contents, 56% of sections read".
  • No headings: no ring, and the label stays as before.

Related fix

Above the first heading, the bar now shows the page title, as the desktop TOC does. It used to keep the last active section after scrolling back to the top, which would contradict a ring at 0%. The if (currentId) guard came from the IntersectionObserver version, where "nothing visible" could mean "between headings". In the scroll-based version, no active heading only happens above the first one.

Code

  • .docu/components/TocProgress.tsx: tocProgress(activeIndex, total, atEnd) and TocProgressCircle.
  • .docu/components/Sidebar.tsx: MobileBar tracks the active heading's index and the end of the page, and renders the ring before the title.

Verification

Built flame's docs and scrolled docs/getting-started/base-path top to bottom and back in Chromium, emulating a 390px phone with touch, in the light and dark themes.

Scroll position Ring Title
Top 0% Base Path & Subpaths
Docs prefix 11% Docs prefix
Bring your own pages 56% Bring your own pages
Verify, end of page 100% Verify
Back to top 0% Base Path & Subpaths, was "Verify" before
  • At every step the ring sat left of the title, vertically centered on it. No page errors.
  • The track stays visible in both themes.
  • 9 new tests in toc-progress.test.ts cover the progress math and the ring markup: position, end of page, clamping, no arc at 0, the dash offset, aria-hidden and the reduced-motion class.
  • 810 flame tests pass. tsc, oxlint, the docs build and the pre-push hook pass.

A circular progress indicator now sits to the left of the current
section's title, inline in the mobile bar's table of contents button.

- It fills with the share of sections reached: the active heading's
  position among the page's headings.
- It completes at the end of the page, since a short last section never
  scrolls up to the anchor offset and so never becomes active.
- 18px ring: a faint track and a primary arc. At 0 only the track is
  drawn, so the round cap shows no dot. The fill animates, except under
  prefers-reduced-motion.
- The ring is decorative. The button's accessible name carries the
  percentage, e.g. "Expand table of contents, 56% of sections read".
- No ring on pages without headings.

Above the first heading the bar now shows the page title, as the desktop
TOC does. It kept the last active section after scrolling back to the
top, which would contradict a ring at 0. The `if (currentId)` guard came
from the IntersectionObserver version, where nothing visible could mean
"between headings". In the scroll-based version it only means "above the
first heading".
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Nov 5, 2026 4:37pm UTC

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Reviewed the whole PR in standard mode (a UI island, not on the build/render, security or plugin path). It adds a reading progress ring to the mobile TOC bar and makes the bar show the page title above the first heading.

  • tocProgress helper: a pure function in TocProgress.tsx that returns the active heading's position among the page's headings. It is clamped to 0..1, returns 0 when there are no headings and 1 at the end of the page.
  • TocProgressCircle: an 18px decorative SVG ring with aria-hidden. It draws no arc at 0, and its dash-offset transition is turned off under motion-reduce.
  • MobileBar scroll tracking: the handler now records the active index and whether the page is scrolled to the end. It also calls setActiveId(null) above the first heading, which matches Toc.tsx on desktop.
  • Accessible name: when headings exist, the TOC button's aria-label now ends with the percentage, for example ", 56% of sections read".
  • Tests and changeset: 9 unit tests for the math and the markup, plus a @docubook/flame patch changeset. A patch bump matches how this repo has shipped other UI features.

What I checked:

  • Mobile scroll source: #scroll-container only scrolls internally at lg and up (lg:overflow-y-auto). On mobile the window scrolls, so window.scrollY and documentElement.scrollHeight are the right values for atEnd.
  • Hydration: #mobile-bar-island is an empty div in the SSR output, so state that exists only on the client cannot cause a hydration mismatch.
  • Validation: toc-progress.test.ts passes (9 of 9) and oxlint reports nothing on the three changed source files.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

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