Repository navigation
feat: replace the heading copy button with a # section link - #312
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
DOCS-1509 Replace the heading copy button with a # section link
ProblemReaders 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' Change
Constraints
UpstreamNo: a Coder design choice; Fumadocs' heading style is deliberate. |
Jesswinters
left a comment
There was a problem hiding this comment.
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
hashchangedoes not makeUserContentAnchorsscroll a second time, becauseuserContentTargetreturnsnullwhen the element the hash points to already exists. ScrollTabletable names are unchanged, because the anchor has no text content.data-cardkeeps the#out of the.prose a:not([data-card])link styling.- Classes such as
scroll-m-28are still generated through thedocs-ui/dist@source. - Calling
useIdbefore the early return keeps the hook order stable.
Review generated by Coder Agents on behalf of @Jesswinters.
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
36da68a to
e972b25
Compare
|
@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: Where the PR stands (e972b25). The What I measured. These are names from Chromium's own accessibility tree (
So swapping in <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 The cost: every heading gets a wrapping Which do you prefer?
I haven't pushed any code for this. Nick asked to hear from you first. Comment generated by Coder Agents on behalf of @nickvigilante. |
|
@nickvigilante, replying to #312 (comment): let's go with option 2, but name the link with visually hidden text, not <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 Why hidden text instead of
Names I measured in Chromium's accessibility tree (
If you want a hover tooltip as well, give it different wording, such as Please also add a check to Comment generated by Coder Agents on behalf of @Jesswinters. |
|
My bad on the |
… 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
|
The merge conflicts are resolved in 20a68b8 (a plain merge of main at df227d6, no rebase). Three files conflicted. In 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
|
Conflicts with main are resolved again in aafefdc (plain merge of origin/main at 8a6b30e, no rebase). Two files conflicted, both in |
Build preview
https://coder-docs-2u155ixwn.coderite.app/ (built from 0205b7b with coder/coder
mainat d3de82f; needs a Vercel login)Merge order
No required order.
mainis merged in again at df227d6 (brand stack, product switcher #391, Fumadocs 16.17 #298), which resolved conflicts ina11y-keyboard.mjs,brand.cssandmdx.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'saria-labelledbyand the link'stitlenaming 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.Design or Fix
@coder/docs-uigets its ownHeading, used forh1toh6in 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.h2,h3orh4has 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.#is CSS::beforecontent 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 namesScrollTablederives 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.ids, URL fragments and the table of contents are unchanged, so every existing link keeps working.followSectionLinkin@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 inDocsShell). 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 existingprefersReducedMotion). It pushes the fragment, fireshashchangeso the table of contents and the raw-anchor handler still hear it, and callsscrollIntoView({ 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.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. Underpointer: coarseits target grows to 44px without moving anything.HEADING_TEXT_LINKSinpackages/docs-ui/src/mdx.tsxtotrue. Both the text and the#then link to the section, and both scroll smoothly.heading.test.tsxcovers that shape.QA
/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.#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.#. Expected: the page scrolls smoothly down to the heading, and the address bar ends in#reset-a-password.#again. Expected: the page jumps straight to the heading with no animation.#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".#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(withoutpr_number, which refers to a coder/coder PR).#on hover, smooth scrollTesting
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 bysr-onlytext equal to the heading text (inline code included), has the "Link to this section" tooltip, and neither carries anyaria-*attribute;textLink; no link without anid; a smooth scroll, fragment andhashchangeon click, with no extra history entry on a second click; no takeover under reduced motion or on modified clicks.mdx.test.tsxcovers the MDX map's default, and that test fails againstmain.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:keyboardgains a heading check in Chromium and Firefox on desktop: no link inside the heading and noaria-*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 frommainit fails in every desktop run, and the description check failed against an intermediatearia-labelledbyplustitlebuild.h2toh4and its height match a build frommainto the pixel in Chromium. A first version differed by 8px where anh3directly follows anh2; the carried-over rule fixed it.test:e2e:stitchasserts the rendered heading shape;a11y:axe(70 scans, 0 new) andtest:e2e:anchorspass.pnpm lintpasses;@coder/docs-ui(206 tests) and@coder/docs-next(406) tests and typecheck pass;@coder/docs-themetests 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.