docs: rename skip link anchor #_top → #main-content (WCAG 2.4.1)#28618
docs: rename skip link anchor #_top → #main-content (WCAG 2.4.1)#28618
#_top → #main-content (WCAG 2.4.1)#28618Conversation
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a0abdd9f-fe08-4f9a-860a-4b9fd872fe24 Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
#_top → #main-content (WCAG 2.4.1)
There was a problem hiding this comment.
Pull request overview
Updates the docs “skip to main content” link to target a clearer anchor (#main-content) for WCAG 2.4.1 naming clarity, and adds a small client-side enhancement to ensure the target exists on Starlight pages.
Changes:
- Update the skip link target from
#_topto#main-content. - Add a new script that assigns
id="main-content"(andtabindex="-1") to the page’s<main>element, including onastro:page-load. - Load the new skip-link enhancement script via
CustomHead.astro.
Show a summary per file
| File | Description |
|---|---|
| docs/src/scripts/skip-link.ts | New script to create a stable skip-link target on <main> and make it focusable. |
| docs/src/components/SkipLink.astro | Changes skip link href to #main-content. |
| docs/src/components/CustomHead.astro | Loads the new skip-link enhancement script site-wide. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
docs/src/scripts/skip-link.ts:27
SkipLinknow targets#main-content, but this script only setsmain.id = 'main-content'when<main>has no existingid. If Starlight (or another integration) adds a differentidto<main>in the future,#main-contentwill never exist and the skip link will break. Consider ensuring#main-contentalways exists (e.g., set the id unconditionally, or insert a dedicated anchor element withid="main-content"without overwriting an existing id).
if (!main.id) {
main.id = 'main-content';
}
- Files reviewed: 3/3 changed files
- Comments generated: 1
| * This script adds `id="main-content"` and `tabindex="-1"` to the `<main>` | ||
| * element so that the skip link (`href="#main-content"`) lands on the correct | ||
| * landmark and keyboard focus is reliably placed there. The `tabindex="-1"` | ||
| * attribute makes the element programmatically focusable without including it | ||
| * in the natural tab order. |
There was a problem hiding this comment.
The docstring says the script “adds id="main-content" and tabindex="-1" to the <main> element”, but the implementation only adds them when the attributes are missing. Either update the comment to reflect the conditional behavior, or change the implementation to always enforce the expected target (#main-content).
This issue also appears on line 25 of the same file.
| * This script adds `id="main-content"` and `tabindex="-1"` to the `<main>` | |
| * element so that the skip link (`href="#main-content"`) lands on the correct | |
| * landmark and keyboard focus is reliably placed there. The `tabindex="-1"` | |
| * attribute makes the element programmatically focusable without including it | |
| * in the natural tab order. | |
| * This script ensures the `<main>` element has `id="main-content"` and | |
| * `tabindex="-1"` when those attributes are missing, so the skip link | |
| * (`href="#main-content"`) lands on the correct landmark and keyboard focus is | |
| * reliably placed there. The `tabindex="-1"` attribute makes the element | |
| * programmatically focusable without including it in the natural tab order. |
The docs skip link targeted
#_top— an anchor name that implies "top of page" rather than "main content", violating WCAG 2.4.1 naming clarity. Starlight doesn't expose a stableidon<main>, so the fix requires both a new anchor target and a script to create it.Changes
SkipLink.astro—href="#_top"→href="#main-content"scripts/skip-link.ts(new) — setsid="main-content"andtabindex="-1"on Starlight's<main>element; re-runs onastro:page-loadto cover client-side navigationCustomHead.astro— importsskip-link.tsalongside the existingsearch-ariaandcopy-button-ariaenhancement scriptsThe
tabindex="-1"makes<main>programmatically focusable without inserting it into the natural tab order.