Repository navigation
fix: move the skip link's focus to the app's main landmark - #329
Merged
brian-smith-tcril merged 1 commit intoOct 27, 2026
Merged
Conversation
The shell's skip link pointed at the shell's own content wrapper, a div with id main-content, while every app renders its primary content in a <main> of its own below it, so activating the link left focus above the app's landmark and the next Tab went back to the top of the page. The link now finds the page's <main> (or the wrapper, when a page has none), makes it focusable and moves focus to it, keeping the hash href as the no-JS fallback. The rule is a page rule, a function from the document to a diagnostic, run by runPageRules, which apps call in their route tests once a page has rendered; the first rule reports an error when a page has more than one <main> without the hidden attribute and a warning when it has none. The migration how-to states the rule: every route should have one <main>, around its primary content, and HTML allows no more than one that is not hidden. The shell's own dev pages now render one and assert the rule in their tests. Resolves openedx#328. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
brian-smith-tcril
added a commit
to brian-smith-tcril/bairf
that referenced
this pull request
Oct 27, 2026
arbrandes
approved these changes
Oct 27, 2026
arbrandes
left a comment
Contributor
There was a problem hiding this comment.
Love the rules idea! 👍🏼
The only nit I have is that we should probably make SkipLink part of the frontend-base API by exporting it. We'll want people that replace the header slot to be able to use it.
This is good to go either way.
|
🎉 This PR is included in version 2.0.0-alpha.17 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
Author
|
Made a follow-up issue for exporting the |
This was referenced Oct 29, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The shell's "skip to main content" link pointed at the shell's own content wrapper, a
<div id="main-content">, while every app renders its primary content in a<main>of its own below it. Activating the link left focus above the app's landmark, so the next Tab went back to the top of the page. The link now finds the page's<main>at click time, makes it focusable and moves focus to it, with the hashhrefkept as the no-JavaScript fallback and the wrapper as the fallback target for a page without a<main>. No app needs to change: every converted app already renders a<main>, and the rule they follow is HTML's own, one<main>per route with no other that is nothidden.Alongside it, a new kind of thing: page rules, functions from a rendered document to a diagnostic, which an app asserts in its route tests once a page has rendered (
expect(runPageRules(document)).toEqual([])). The first rule reports more than one visible<main>as an error and none as a warning. The rules have no runtime part: there is no moment at which a page "has rendered" that the shell can see (the decision log's entry 6 walks through the three runtime shapes that were tried and why each guessed wrong), while a route test's author knows exactly when. The shape is meant to take more rules from the migration how-to; the next candidate is the document title (Decisions, entry 7).Resolves #328.
What changed
shell/header/SkipLink.tsx(new), rendered byHeader.tsxin place of the anchor: samehref, plus a click handler that focuses the first<main>withouthidden, else themain-contentwrapper, settingtabindex="-1"when the target has no tabindex and callingscrollIntoView; with neither present the anchor acts as before.shell/style.scss:main[tabindex="-1"]:focus { outline: none; }.shell/rules/:types.ts(Diagnostic,PageRule),mainLandmark.ts(the rule, with the HTML spec URL),index.ts(the list andrunPageRules), exported from the package root.shell/dev/devHome/HomePage.tsx,shell/dev/slotShowcase/SlotShowcasePage.tsx: the dev site's pages render their containeras="main", and each gets a test asserting the rule.docs/how_tos/migrate-frontend-app.md: a section, "Render one<main>landmark per route", after the document-title section, ending with the assertion for route tests.SkipLink.test.tsx(render; focus and tabindex; a hidden<main>passed over; an existing tabindex kept; the wrapper fallback; no target),rules/mainLandmark.test.ts(one passes; hidden not counted; two is an error; none is a warning),rules/index.test.ts(runPageRuleson fake rules passed as its second parameter: each rule gets the document,[]when all pass, the failing rules' diagnostics otherwise), the two dev-page tests.Not here: frontend-template-application's own nested
<main>(src/Main.tsxaroundsrc/example/ExamplePage.tsx), which this rule reports and which is a one-line fix there; the test-site's pages, which also render no<main>and are scoped narrowly on purpose; the runtime's not-found and error pages, which replaceShellentirely on an unmatched path (pre-existing); focus after client-side navigation, the issue's last paragraph, which is its own issue.Testing
npm run lint,npm run typecheck,npm test(551 tests, 62 suites) andnpm run buildpass, with the test site installed from the packed tarball as CI does. Manual check on the shell's dev site (npm run dev): the record below, every box checked.Decisions
Why the id stays, why the rule is "should", what a page rule is and why it is named that, why the rules run in tests and not on the dev site, which rules were considered and left out.
Full decision log
Decisions — the skip link and page rules (#328)
Decisions made while implementing, 2026-10-26. The direction the issue's discussion settled (the skip link finds the landmark itself; no app puts an id on anything) is the starting point and is not re-argued.
The skip link finds the
<main>at click time; the wrapper's id stays.shell/header/SkipLink.tsxkeepshref="#main-content"and handles theclick: the first
<main>without thehiddenattribute, else theelement with
id="main-content", else nothing. The id stays on theshell's content wrapper in
DefaultLayout.tsxfor two reasons: it isthe no-JavaScript target, and it is the fallback for a page that
renders no
<main>. The shell does not render<main>itself: theARIA Authoring Practices Guide asks for one main landmark per page,
top-level, and every app already renders its own.
The handler prevents the default only when it has a target. With a
target it calls
preventDefault, so the URL gains no hash, setstabindex="-1"only when the element has notabindex(an app's ownvalue is kept), then
focus()andscrollIntoView(). Browsers scrollto a hash target but do not reliably move focus to a non-focusable
element, so without this the next Tab returns to the top of the page.
With no target the click falls through to the anchor, the same as any
skip link whose target is missing. The handler is typed as React's
MouseEvent: a link activated with Enter dispatchesclick, so onehandler covers keyboard users.
One focus style, scoped.
main[tabindex="-1"]:focus { outline: none }in
shell/style.scss, scoped to the programmatically focusable case soan app's own focus styling on a
<main>is untouched.The rule is HTML's, per route, and phrased as "should". The HTML
Living Standard: "A document must not have more than one main element
that does not have the hidden attribute specified." So a hidden second
<main>is allowed, and the rule is per rendered route, not per app:which component renders the
<main>(a layout route, or each page) isthe app's choice. Having one is "should", since the skip link still
works through the wrapper fallback without it; the "no more than one
visible" part is HTML's "must". That split gives the rule its two
levels: more than one visible
<main>is an error, none is a warning.Page rules are a new category, named for what they are. Nothing in
frontend-base judged the rendered document before this: the runtime
throws on misconfiguration at startup and reports failures through the
logging service. The first draft was one hook named for its rule
(
useMainLandmarkCheck); review asked what category it belongs to.Settled: rules about what a route renders, each yielding a diagnostic
(TypeScript's and the language servers' word for a message with a
severity).
shell/rules/types.tsdefinesDiagnostic(
level: 'error' | 'warning',message) andPageRule(
(document: Document) => Diagnostic | undefined); each rule is a filedeclared against that type (
const mainLandmark: PageRule = ...) withits own test;
shell/rules/index.tslists them and exportsrunPageRules(document), which returns the diagnostics of every rulethat fails. "Page" scopes the type to a rendered route's document; a
rule about site config would take the config and be a different type.
Rejected names: "check" (says nothing about the output), "audit" (in
accessibility tooling it names a whole run, and not every rule is an
accessibility one). The level union stays inline: the repository has
no severity or log-level type to reuse (the logging service encodes
levels as two methods,
logErrorandlogInfo), and in a test anydiagnostic fails the assertion while a suite that wants to tolerate
warnings can filter on
level.The rules run in tests, not on the dev site. Three runtime shapes
were built and each was wrong about when: a hook called from
Shellafter its own commit (
SiteProviderrenders nothing until the themehas loaded, so the page was not there yet); a component mounted beside
the page inside the provider (a page that renders its
<main>onceits data arrives, as Learning's tab page does after the course
metadata query, would warn on every load and never correct itself);
then a
MutationObserverwith a quiet period gated on the routerbeing idle and React Query having no fetch in flight. The plan's
"When the document can be judged" lists every source of change in the
document after a navigation and shows that only two of them expose a
signal; the rest (the provider's gate, component-level lazy loading,
data loading outside React Query, later interaction) leave "the page
has rendered" a heuristic. A static check cannot replace it either: a
lint rule sees one file, and both real cases cross files
(frontend-template-application's
Main.tsxaroundExamplePage.tsx, Learning'sLoadedTabPageunderTabPage). Theplace where "the page has rendered" is actually known is a route test:
its author renders the route, waits for the content and then asserts.
So the rules run there:
runPageRulesis exported from the packageroot beside
initializeMockApp, the how-to says to assertexpect(runPageRules(document)).toEqual([])once the page hasrendered, and nothing in the shell guesses at timing. Lost: a
developer who writes no route test gets no diagnostic. If a dev-site
diagnostic is wanted later it comes back for instant rules only (more
than one visible
<main>is a violation whenever observed) on anymutation, with no settle heuristic, as its own change.
Rules considered and not included.
documentTitle, from thehow-to's "Set the document title on every route-level page": an empty
document.titleonce the page has rendered would be the finding,since the shell's generated
index.htmlsets no title; left for alater PR as the second rule, noted in this PR's description. A rule
that an app chunk re-ships Paragon's
:rootdeclarations (ADR 0008,the how-to's "must NOT import" box): rejected, because the signal
depends on the build's cascade-layer wrapping being present and on
same-origin stylesheets, jsdom cannot parse
@layerso its test wouldrun against hand-built sheets, and ADR 0008's layering already
neutralises the failure. A duplicate-id rule: no sentence in the docs
asks for it, and a third-party widget is the likeliest thing to trip
it.
Tests. The rule is tested alone on document markup
(
shell/rules/mainLandmark.test.ts: one passes, hidden ones are notcounted, two is an error, none is a warning).
runPageRulestakes therules as a second parameter defaulting to the list, so its test
(
shell/rules/index.test.ts) passes plain functions instead of mockingrule modules, which would have to grow with the list: it calls each
rule with the document, returns nothing when every rule passes, and
returns the diagnostics of the rules that fail, which is the shape an
app's assertion relies on. The shell's dev pages,
HomePageandSlotShowcasePage, each get a test that renders thepage under an intl provider and a memory router and asserts
runPageRules(document)is empty: the shell asserting its own rulethe way the how-to tells apps to, and what fails if the
<main>isdropped again. The skip link's tests are the handler's cases (target
found, a hidden
<main>passed over, an existing tabindex kept, thewrapper fallback, no target).
The how-to gets a section of its own. The rule first went into the
Main.jsxbullet of the file layout, which impliedMain.jsxrendersthe
<main>; it does not have to. "Render one<main>landmark perroute" now follows "Set the document title on every route-level page":
the shell renders no
<main>, apps are expected to render it aroundprimary content in each route, HTML allows no more than one without
hidden, the skip link moves focus to it, and route tests assert itwith
runPageRules.Left for their own changes. frontend-template-application renders
a second
<main>inside the first (src/Main.tsxandsrc/example/ExamplePage.tsx), which this rule reports; a one-linefix there, with the assertion in its route test. The test-site's
ExamplePageandAuthenticatedPagerender aContainerwithout<main>and have no page tests; the test-site is scoped narrowly onpurpose, so that is left alone here. Focus after client-side
navigation, which the skip link does not address, is the issue's last
paragraph and its own issue.
The shell's dev pages render a
<main>. Preparing the manual passshowed that the dev site's own pages (
/dev,/slots) rendered no<main>, so the skip link only ever reached the fallback there. Bothpages' Paragon
Containernow rendersas="main", and their newtests (entry 8) hold it. The runtime's
NotFoundPageandErrorPagehave no
<main>either; when they render as the root route'serrorElement(a path no route matches) they replaceShellentirely, so there is no header and no skip link there, which is
pre-existing and its own question.
Manual testing
Manual testing — the skip link (#328)
What the automated suite cannot show: where focus actually lands in a browser and what a keyboard user sees. The page rule has no runtime part; it runs in tests.
Environment
skip-link-main-landmark,npm run dev(builds, then serves the shell's dev site athttp://apps.local.openedx.io:8080)./dev(the dev home) and/slots(the slot showcase), both of which render a<main>as of this branch. A path no route matches (/nope) is no use: the root route'serrorElementrenders the not-found page in place ofShell, so there is no header and no skip link on it (pre-existing).Verify by hand
/dev, press Tab: "Skip to main content." appears at the top of the page as the focused element (it is visually hidden until focused).<main>— press Enter on the link: in the console,document.activeElement.tagNameisMAIN; the URL did not gain#main-content; no focus ring is drawn on the<main>.<main>falls back to the wrapper — temporarily removeas="main"fromHomePage.tsx, let the dev server rebuild, reload/dev; Tab to the skip link, Enter:document.activeElement.idismain-content. Revert the edit.Left to the automated suite
shell/header/SkipLink.test.tsx.shell/rules/mainLandmark.test.ts; the dev pages satisfying it:shell/dev/devHome/HomePage.test.tsx,shell/dev/slotShowcase/SlotShowcasePage.test.tsx.Results
2026-10-26, Brian. All four boxes passed on the dev site.
/nopeshowed the not-found page with no header or footer: the root route'serrorElementrenders it in place ofShell(pre-existing). Earlier passes on the same day exercised a runtime version of the rule (console diagnostics on reload and navigation, the error for two<main>elements, the hidden exception); that version was removed in favour of running the rule in tests (decision 6), and those observations no longer apply to the branch.🤖 Generated with Claude Code