Skip to content

feat: replace the heading copy button with a # section link - #312

Merged
nickvigilante merged 6 commits into
mainfrom
vigilante/heading-anchor-links
Nov 24, 2026
Merged

nickvigilante merged 6 commits into
mainfrom
vigilante/heading-anchor-links

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Build preview

https://coder-docs-2u155ixwn.coderite.app/ (built from 0205b7b with coder/coder main at d3de82f; needs a Vercel login)

Merge order

No required order. main is merged in again at df227d6 (brand stack, product switcher #391, Fumadocs 16.17 #298), which resolved conflicts in a11y-keyboard.mjs, brand.css and mdx.tsx. #298 (Fumadocs 16.17) doesn't touch the heading.

Review feedback applied (879af8b): Jess's option 2 with hidden text. The # link now sits beside the heading rather than inside it, is named by visually hidden text, and the PR uses no ARIA at all: the heading's aria-labelledby and the link's title naming are gone.

Opened by Coder Agents for @nickvigilante.

Summary

Readers told us the icon next to each heading is confusing: it looks like "go to this section" but copies the URL, while the heading text itself is the real link. Headings are now plain text, followed by a # link to the section that appears on hover and keyboard focus. Its accessible name is the heading text, from visually hidden text inside the link, so a screen reader announces "Coder Workspaces, link" rather than "#" or "Copy Anchor Link". Hovering the # shows a "Link to this section" tooltip. Clicking it, or an entry in either "On this page" list, scrolls smoothly to the section, or jumps straight there when reduced motion is on.

Before and after, hovering a heading

Design or Fix

  • @coder/docs-ui gets its own Heading, used for h1 to h6 in the MDX map in place of Fumadocs' Heading. It renders <div data-heading><hN id>text</hN><a data-heading-anchor href="#id" title="Link to this section"><span class="sr-only">text</span></a></div>. A link inside a heading adds its name to the heading's, so the link sits beside it: the heading's name is its text once and the link's name is the heading text, both from content, with no ARIA. The hidden text is the heading's plain text, inline code included. The tooltip uses different wording so screen readers don't read the name twice.
  • The wrapper has no block padding or border, so the heading's prose margins still collapse through it and the spacing around headings is unchanged. Two prose rules are carried over to the wrapper: the element after an h2, h3 or h4 has no top margin (including a heading that follows straight on), and a heading that opens the page has none either. The # is positioned in a 1.75rem slot at the end of the wrapper, as the flex layout did before, and takes the heading's font size.
  • The # is CSS ::before content with empty alt text (content: "#" / "", behind @supports), so it isn't part of the link's name. The heading's text, the search index and the table names ScrollTable derives from headings never include the link. Browsers without CSS content alt text (Firefox before 128, Safari before 17.4) still show the # and read it before the hidden text.
  • Heading ids, URL fragments and the table of contents are unchanged, so every existing link keeps working.
  • One helper, followSectionLink in @coder/docs-ui, handles the # link and both tables of contents (the desktop list and the small-screen list under the title, through a delegated listener in DocsShell). It only takes over a plain left click on a same-page link when reduced motion is off (the system setting or the site's own motion setting, through the existing prefersReducedMotion). It pushes the fragment, fires hashchange so the table of contents and the raw-anchor handler still hear it, and calls scrollIntoView({ behavior: "smooth" }). A second click on the same # scrolls back without adding a history entry. Reduced motion, Cmd, Ctrl or Shift clicks, and a target hidden in a closed <details> or an inactive tab (which the tab and raw-anchor handlers reveal) are left to the browser's own navigation.
  • Styling lives in brand.css: the # always reserves its 24px slot and only changes opacity, so hovering causes no layout shift. It shows on heading hover and on :focus-visible, and is always visible on devices without hover (phones and tablets), where "on hover" can't work. Under pointer: coarse its target grows to 44px without moving anything.
  • Reverting the heading-text decision is one line: set HEADING_TEXT_LINKS in packages/docs-ui/src/mdx.tsx to true. Both the text and the # then link to the section, and both scroll smoothly. heading.test.tsx covers that shape.

QA

  1. Open /admin/users/ on a window at least 1280px wide. Look at the "Reset a password" heading. Expected: the heading text is plain text, not a link: no pointer cursor, and clicking it does nothing.
  2. Hover the heading. Expected: a grey # fades in just to the right of the text, and nothing else on the page moves. Rest the pointer on the #. Expected: after a moment, a tooltip reads "Link to this section". The space above and below the heading is the same as on production.
  3. Scroll back to the top and click the #. Expected: the page scrolls smoothly down to the heading, and the address bar ends in #reset-a-password.
  4. Turn on reduced motion (macOS: System Settings, Accessibility, Display, Reduce motion; Windows: Settings, Accessibility, Visual effects, Animation effects off), or set Motion to Reduced in the site's display settings. Scroll to the top and click the # again. Expected: the page jumps straight to the heading with no animation.
  5. Press Tab from the top of the page until a heading's # gets a focus ring. Expected: the # appears while focused. With VoiceOver or NVDA on, it's announced with the heading's text, for example "Configure SSO, link".
  6. With reduced motion off again, scroll to the top and click "Reset a password" in the "On this page" list on the right. Expected: the page scrolls smoothly to the heading. With reduced motion on, it jumps.
  7. On a phone, open the same page. Expected: each heading shows its # without hovering. Open "On this page" under the title and tap "Reset a password". Expected: a smooth scroll to the heading.

The tooltip is the browser's own, so it appears on mouse hover only, not on keyboard focus or touch.

Steps 1 to 6 were checked in Playwright's Chromium and Firefox on the fixture corpus's "Next steps" heading (see Testing), not by hand; the deployed preview's markup and CSS were checked on /admin/users/; the screen-reader part of step 5 was checked through the accessible name, not with a real screen reader.

Pages to compare

The preview needs a Vercel login. It is a fixed deployment of 0205b7b, not a branch alias, so a later push needs a new run of docs-pr-preview.yml (without pr_number, which refers to a coder/coder PR).

What to check Production Preview
Heading text, # on hover, smooth scroll https://coder.com/docs/admin/users/ https://coder-docs-2u155ixwn.coderite.app/admin/users/
A long page with many headings https://coder.com/docs/install/server/kubernetes/ https://coder-docs-2u155ixwn.coderite.app/install/server/kubernetes/

Testing

  • heading.test.tsx (new, 7 tests): the heading holds no link or button and its name is its text; the # link follows it, is named by sr-only text equal to the heading text (inline code included), has the "Link to this section" tooltip, and neither carries any aria-* attribute; textLink; no link without an id; a smooth scroll, fragment and hashchange on click, with no extra history entry on a second click; no takeover under reduced motion or on modified clicks. mdx.test.tsx covers the MDX map's default, and that test fails against main.
  • section-scroll.test.ts (new, 4 tests): smooth scroll and fragment; reduced motion, modified clicks and other buttons left alone; other pages, missing ids and sections hidden in an inactive tab, closed <details> or [hidden] left alone; percent-encoded fragments. toc-smooth-scroll.test.tsx (new, 3 tests): both tables of contents scroll smoothly, they jump under reduced motion, and body links aren't taken over.
  • a11y:keyboard gains a heading check in Chromium and Firefox on desktop: no link inside the heading and no aria-* on the heading, the wrapper or the link; the link is named exactly the heading text and its tooltip is "Link to this section"; in Chromium's own accessibility tree (Accessibility.getFullAXTree, because Playwright's name computation hides a doubled heading name), the heading is named exactly its text and the link doesn't repeat its name as its description; the # shows on focus and hover without resizing the heading; and the # and the heading's desktop TOC entry each jump under reduced motion and scroll under full motion, with the fragment updated. All 8 runs pass. Against a build from main it fails in every desktop run, and the description check failed against an intermediate aria-labelledby plus title build.
  • Heading spacing: on 6 fixture pages (28 headings), the gap above and below each h2 to h4 and its height match a build from main to the pixel in Chromium. A first version differed by 8px where an h3 directly follows an h2; the carried-over rule fixed it.
  • test:e2e:stitch asserts the rendered heading shape; a11y:axe (70 scans, 0 new) and test:e2e:anchors pass.
  • pnpm lint passes; @coder/docs-ui (206 tests) and @coder/docs-next (406) tests and typecheck pass; @coder/docs-theme tests pass.

Upstream

No. Fumadocs' heading anchor is a deliberate style choice, and this is a Coder design decision.

Linear: DOCS-1509


🤖 Built with AI assistance.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
coder-docs Ready Ready Preview Nov 9, 2026 6:22pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
coder-docs-router Skipped Skipped Nov 9, 2026 6:22pm UTC

Request Review

@linear-code

linear-code Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
DOCS-1509 Replace the heading copy button with a # section link

Filed via Coder Agents for @Vigilante.

Problem

Readers flagged that the icon button next to each docs heading copies the section URL instead of going to the section. That's confusing, and it's an antipattern: an icon beside a heading reads as a link. Today the heading text is the link, and the button is a copy action that Fumadocs' Heading component renders.

Change

  • Headings render as plain text, not links.
  • Hovering or focusing a heading shows a # to its right. The # is an <a href="#id"> to that section, and its accessible name is the heading text.
  • Clicking the # scrolls smoothly to the heading unless reduced motion is on (system setting or the site's motion setting). With reduced motion, it jumps straight there.
  • Making the heading text a link again must be a one-line change, in case readers object.

Constraints

  • No layout shift: the # reserves its space and only changes opacity.
  • The # is visible on keyboard focus and on devices without hover, and meets the 24 by 24 target size.
  • The heading's id and the URL fragments don't change, so existing links keep working.

Upstream

No: a Coder design choice; Fumadocs' heading style is deliberate.

Review in Linear

@Jesswinters Jesswinters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the full diff against main, plus the code it touches (Fumadocs 16.15.14 Heading, UserContentAnchors, the TOC hashchange listener, ScrollTable heading names, and the Tailwind @source scan of docs-ui/dist). @coder/docs-ui and @coder/docs-theme test, typecheck and lint all pass locally (202 + 30 tests), and CI is green.

I found no P0 or P1 issues, so I'm approving. Two P2s and one P3 are below.

P2: the heading's own accessible name now repeats the heading text. See the inline comment. This is not worse than main, where the name ends in "Copy Anchor Link", but it's a one-line fix.

P2: merge conflict. #310 has landed, so apps/docs/scripts/a11y-keyboard.mjs conflicts, as the description expects. It's the only conflicting file.

P3: HEADING_TEXT_LINKS plus the headingTextLinks option are two ways to revert one decision, and nothing calls the option today. One of them would be enough. Not blocking.

Other things I checked and found fine:

  • The synthetic hashchange does not make UserContentAnchors scroll a second time, because userContentTarget returns null when the element the hash points to already exists.
  • ScrollTable table names are unchanged, because the anchor has no text content.
  • data-card keeps the # out of the .prose a:not([data-card]) link styling.
  • Classes such as scroll-m-28 are still generated through the docs-ui/dist @source.
  • Calling useId before the early return keeps the hook order stable.

Review generated by Coder Agents on behalf of @Jesswinters.

Comment thread packages/docs-ui/src/heading.tsx Resolved
Readers expect the icon beside a heading to go to that section, but
Fumadocs' heading button copies the URL instead, and the heading text was
the real link. Headings are now plain text followed by a # link that
appears on hover and focus, is named after the heading, and scrolls
smoothly to the section unless reduced motion is on.

Linking the heading text again is one constant in the MDX map, or the
headingTextLinks option per call, in case readers miss it.

Assisted-by: AI
The # link's tooltip and accessible name are now both the heading text,
from its title alone: an aria-label as well would repeat the text as its
description, and the # is CSS content with empty alt text so it doesn't
become the name. The heading is labelled by its own text, so its name no
longer repeats the link's.

Entries in either "On this page" list now scroll smoothly to their heading
like the # link does, through one shared helper, and still jump under
reduced motion. The headingTextLinks option goes; the constant in the MDX
map stays the single switch for linking heading text again.

Assisted-by: AI
@nickvigilante
nickvigilante force-pushed the vigilante/heading-anchor-links branch from 36da68a to e972b25 Compare November 4, 2026 21:01
@vercel
vercel Bot temporarily deployed to Preview – coder-docs-router November 4, 2026 21:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – coder-docs November 4, 2026 21:01 Inactive
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@Jesswinters, a question before you take another look. Nick mentioned you'd rather we use alt text than ARIA labels, so I tested the options rather than guessing. I agree that native text is better: aria-label still isn't translated reliably (Adrian Roselli's July 2025 retest), and alt and title are translated like any other text.

Where the PR stands (e972b25). The # link has no aria-label. Its name and its tooltip both come from title, and the # glyph is CSS content: "#" / "". The only ARIA left is aria-labelledby on the heading, from your suggestion, which stops the heading's name repeating.

What I measured. These are names from Chromium's own accessibility tree (Accessibility.getFullAXTree). I couldn't read Firefox's tree in this setup, so I don't have Firefox numbers.

Markup Heading name Link name
This PR now "Next steps" "Next steps"
<img alt> with the link inside the <h2>, no ARIA "Next stepsNext steps" "Next steps"
Visually hidden text inside the link, inside the <h2> "Next stepsNext steps" "Next steps"
aria-label plus title on the link "Next steps Next steps" "Next steps", repeated as its description
<img alt title> with the link beside the <h2>, no ARIA "Next steps" "Next steps"

So swapping in alt text on its own doesn't work. A heading takes its name from its contents, so any named link inside the <h2> adds its name to the heading's. The only no-ARIA arrangement that gets both names right is the last row, with the link moved out of the heading:

<div class="group/heading ...">
  <h2 id="next-steps">Next steps</h2>
  <a href="#next-steps"><img src=".../hash.svg" alt="Next steps" title="Next steps"></a>
</div>

The title goes on the <img>, not the link: on the link, Chromium reads it again as the description. This version would also drop the CSS alt-text trick, so Firefox before 128 and Safari before 17.4 would announce the heading text rather than "#".

The cost: every heading gets a wrapping <div>, and I'd have to check that the prose spacing and the no-layout-shift guarantee still hold. Several things look for the # inside the heading and would need updating: the Markdown twin and search index, the ScrollTable table names, and the stitch and a11y:keyboard tests. It's a moderate rework of Heading, not a one-line change.

Which do you prefer?

  1. Merge as is, with title naming the link and aria-labelledby on the heading.
  2. Move the link beside the heading and use <img alt title>, with no ARIA anywhere. That could happen in this PR or in a follow-up.

I haven't pushed any code for this. Nick asked to hear from you first.

Comment generated by Coder Agents on behalf of @nickvigilante.

@Jesswinters

Copy link
Copy Markdown
Collaborator

@nickvigilante, replying to #312 (comment): let's go with option 2, but name the link with visually hidden text, not <img alt> or title. Please also remove the aria-labelledby from the heading, so the PR uses no ARIA at all.

<div class="group/heading ...">
  <h2 id="next-steps">Next steps</h2>
  <a href="#next-steps" data-heading-anchor><span class="sr-only">Next steps</span></a>
</div>

Keep the # as CSS ::before with content: "#" / "", so the glyph stays out of the link's name.

Why hidden text instead of title:

  • Browsers only use title as a name when there's nothing else. Support across screen readers is less consistent than for real text, and only mouse users ever see the tooltip.
  • Hidden text is ordinary page text, so translation tools handle it the same way they handle title and alt.
  • It needs no image file.

Names I measured in Chromium's accessibility tree (Accessibility.getFullAXTree). I couldn't check Firefox or a real screen reader.

Markup Heading name Link name
Link beside the <h2> with hidden text and content: "#" / "" "Next steps" "Next steps"
The same, but with plain content: "#" "Next steps" "# Next steps"
Empty link with title, inside the <h2>, no ARIA "Next steps Next steps" "Next steps"
alt on the <a> (not valid on <a>, so it's ignored) "Next steps" "" (no name)

If you want a hover tooltip as well, give it different wording, such as title="Link to this section", so screen readers don't read the name twice.

Please also add a check to a11y:keyboard that the heading's name equals its text, using the browser's accessibility tree rather than ariaSnapshot. ariaSnapshot misses the doubled name.

Comment generated by Coder Agents on behalf of @Jesswinters.

@Jesswinters

Copy link
Copy Markdown
Collaborator

My bad on the alt text @nickvigilante, I forgot that was for img's and not a tags. title kind of works but the best option is hidden text. Cold brain. 🫠

… ARIA

A link inside a heading adds its name to the heading's, so the heading
was labelled by its own text through aria-labelledby, and the link was
named by its title. Review asked for no ARIA at all and for real text
rather than title, which screen readers support less consistently and
only mouse users see.

The link now follows the heading inside a plain wrapper and is named
by visually hidden text, so both names come from content. The # stays
a CSS glyph with empty alt text. The wrapper has no block padding, so
the heading's prose margins still collapse through it; the h2/h3/h4
"next sibling has no top margin" rule and the first-child reset are
carried over to the wrapper. The tooltip now says "Link to this
section" so it doesn't repeat the name.

Assisted-by: AI
Resolves the a11y-keyboard header comment, which both sides edited.

Assisted-by: AI
Resolves conflicts in the heading anchor change against the brand stack,
product switcher, and Fumadocs 16.17 work that landed on main.
In brand.css the sidebar panel and collapsed sidebar rules that main
removed stay removed. In mdx.tsx the headings map is spread after the
shared engine components. In a11y-keyboard.mjs both the heading # link
check and main's More contrast drawer switcher check are kept.

Assisted-by: AI
@nickvigilante
nickvigilante requested a review from a team as a code owner November 23, 2026 18:59
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

The merge conflicts are resolved in 20a68b8 (a plain merge of main at df227d6, no rebase). Three files conflicted. In packages/docs-theme/src/brand.css I kept the heading # link rules and dropped the [data-sidebar-panel].opacity-0 and #nd-sidebar[data-collapsed] rules, which main had already removed with the Fumadocs 16.17 upgrade; main's old .group/heading > button rule is gone because the copy button no longer exists. In packages/docs-ui/src/mdx.tsx main moved the shared components into engineComponents, so the map now spreads engineComponents and then this PR's headings. In apps/docs/scripts/a11y-keyboard.mjs both sides are kept: the heading # link check and main's More contrast drawer switcher check, with the header comment merged.

Nothing in this PR was superseded by main. Builds, typecheck, lint and format are clean, and the docs-ui (206), docs-next (406), docs-theme (34) and apps/docs (383) tests pass locally; the e2e suites are left to CI. I also updated the test counts and the merge note in the PR body. The linked build preview is still of 0205b7b.

Resolves conflicts in the MDX component map and its tests against the
cards work on main. Both the heading import and main's icon import stay,
and the heading test sits beside the Card tests.

Assisted-by: AI
@nickvigilante

nickvigilante commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Conflicts with main are resolved again in aafefdc (plain merge of origin/main at 8a6b30e, no rebase). Two files conflicted, both in @coder/docs-ui. In src/mdx.tsx I kept this PR's Heading import together with main's ExternalLinkMark import; the map still spreads engineComponents and then headings, and main's DocsCard is untouched since it renders its own h3 rather than going through the heading map. In src/mdx.test.tsx I kept the heading # link test and main's four Card tests side by side. Builds, lint and format are clean, and the docs-ui (210), docs-next (406), docs-theme (34), docs-transforms (460) and apps/docs (386) tests pass locally. Removing headings from the map makes the heading test fail.

@nickvigilante
nickvigilante merged commit f847561 into main Nov 24, 2026
32 of 34 checks passed
@nickvigilante
nickvigilante deleted the vigilante/heading-anchor-links branch November 24, 2026 17:41

This branch is waiting to be deployed

1 active (outdated), 2 inactive (outdated), and 1 waiting deployments
docs-preview — aafefdcf Waiting Nov 23, 2026 by nickvigilante via preview / deploy preview #110
Preview — 0205b7b4 Deployed Nov 9, 2026 by vercel[bot]
Preview – coder-docs-router — e972b25b Deployed Nov 4, 2026 by vercel[bot]
Preview – coder-docs — e972b25b Deployed Nov 4, 2026 by vercel[bot]
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.

2 participants