Skip to content
SprecherEast
Issue 574

feat: "On this page" menu that follows the reader on posts and events

Back to our plan
Done
enhancementfrontenduxpriority: high

Problem

In plain words: long posts and events (the I-94 post has a short version, a map, who gains, a timeline, money, next steps) can only be read by scrolling. Add a small "On this page" list of the article's sections that stays in view as you read: click a section to jump there, and the section you're reading is highlighted. On a phone it's a compact menu at the top that stays in reach.

Summary of the owner's request (2026-11-02, Claude in Chrome side panel): he wants a sticky navigation bar on the left or right, a small menu so people don't keep scrolling, where clicking a header or subheader takes them straight to that section. Ease of navigation and intuitiveness are paramount, and he asked for a small change toward that.

Today (checked): src/platform/ui/DetailLayout.tsx puts the article beside an 18rem sidebar from lg (960px), and the whole sidebar is sticky (lg:sticky lg:top-24). On posts it holds Related Posts, You May Also Like, Upcoming Events and Get Involved; on events, Upcoming Events and Stay in the Loop. Nothing on the site lists an article's sections. The sticky site header is 4.5rem (--header-height).

Proposed fix

Where it sits (decided here, a layout choice):

  • From lg (960px): a right-hand rail holding only "On this page", sticky under the site header. The related lists, upcoming events and the call to action move below the article, which is where phones and tablets already show them, so every width reads the same way.
  • Why not put it at the top of today's sticky sidebar: that sidebar is taller than a laptop screen, so a sticky block that tall can't keep its own top part and the rest in view (likely already true today for its lower cards; confirm with a 1280×720 screenshot before building). A left rail beside the right sidebar would need three columns, which don't fit the 64rem content width between 960 and 1279px.
  • Below lg: a compact bar under the site header, "On this page" plus the current section's name, that opens a list of the sections. Built on the native <details>/<summary>, so it works with keyboard and screen readers without extra code; choosing a section closes it.

Behaviour:

  • Lists the article's h2 sections with their h3 subsections indented, using headingAnchors from the issue "Section links inside articles" (same ids).
  • Shown only when the article has 3 or more h2/h3 headings; otherwise nothing renders and the layout is the same as without it.
  • Jumps are plain #id links (they work without JavaScript, and the address can be shared). Smooth scrolling via CSS scroll-behavior: smooth on html, under motion-safe only; globals.css already turns it off for reduced motion.
  • The current section is found with IntersectionObserver in a small client component, marked aria-current="location" and styled with theme tokens. This is the only client code; the list itself renders on the server.
  • A nav landmark labelled "On this page"; links at least 44px tall on touch; visible focus ring; the bar never covers a heading after a jump (scroll-mt from the anchors issue plus the bar's height on phones).

Native first, one line per step:

  1. Native: CSS position: sticky, scroll-margin-top, scroll-behavior, HTML <details>, the browser's IntersectionObserver, #fragment links. Payload and Next.js have no table-of-contents feature (checked in @payloadcms/richtext-lexical 3.91.0's feature list).
  2. Official plugins: none for a published-page table of contents in @payloadcms/* or Next.js.
  3. Open source: tocbot (MIT, 4.36.8, updated 2026-05) scans the page in the browser and builds the list. Not used: the server already knows the headings, so it would only add client JavaScript and a second source of ids. Weekly downloads weren't checkable from this session.
  4. Our code: one small shared component in src/platform/ui/ (OnThisPage, server, with a tiny client part for the highlight) and a nav slot on DetailLayout. Both pages pass headingAnchors(content).

Docs and rules: docs/ui/component-set.md (new OnThisPage, DetailLayout's new slot), the gallery, and docs/project.md's note that a card preview never appears in an article's layout (#532) still holds: this menu only lists the article's own headings.

Acceptance criteria

  • Not done: The I-94 post shows "On this page" with its sections; a post with fewer than 3 headings shows none and looks as before.
  • Not done: At 1024, 1280 and 1920: the menu stays in view while scrolling the whole article, and the related lists, upcoming events and call to action appear below the article.
  • Not done: At 320, 430 and 768: the compact bar stays under the site header, opens and closes by tap, Enter and Space, and choosing a section closes it and lands on that heading, not hidden.
  • Not done: The current section is highlighted while scrolling and exposed as aria-current="location".
  • Not done: Keyboard only: Tab reaches every link in order, with a visible focus ring; a screen reader announces a navigation region named "On this page".
  • Not done: With reduced motion on, jumps are instant.
  • Not done: Contrast of every state (normal, current, hover, focus) meets WCAG AA in light and dark mode.
  • Not done: Screenshots of the I-94 post and the Nov 10 event at the six widths (320, 430, 768, 1024, 1280, 1920), light and dark, are in the PR; axe and the component tests pass.

Area

frontend, ux

Priority

high


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab