Skip to content

Improve navigation for screen readers - #258

Open
david-crespo wants to merge 12 commits into
mainfrom
a11y-nav
Open

david-crespo wants to merge 12 commits into
mainfrom
a11y-nav

Conversation

@david-crespo

Copy link
Copy Markdown
Contributor

Prompted by feedback that RFD links here don't work with screen readers. Next.js includes a route announcer for this; React Router leaves it to the app, so here we add one.

🤖 summary

New e2e tests cover the announcement, both focus behaviors (moved to content after navigating to an RFD, left alone on the filter input after navigating home), and the skip link being first in tab order.

@vercel

vercel Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
rfd-site Ready Ready Preview Nov 6, 2026 10:02pm UTC

Request Review

@david-crespo
david-crespo requested review from benjaminleonard and fakemonster and removed request for benjaminleonard August 18, 2026 15:23
david-crespo added a commit to oxidecomputer/console that referenced this pull request Aug 18, 2026
Similar deal to oxidecomputer/rfd-site#258

## 🤖 summary

A client-side nav doesn't tell a screen reader anything: React Router
swaps the DOM in place and focus stays on the link that was clicked,
which usually isn't in the document anymore. Next.js ships a route
announcer for this; RR leaves it to the app.

`useRouteAnnouncer` in `RootLayout` announces the crumbs deepest-first
("Instances, mock-project, Projects") through the react-aria live
announcer we already use for toasts and field errors. Polite rather than
assertive so it doesn't preempt the toast on flows that toast and then
navigate. It also puts focus on the existing skip link target, but only
when focus has fallen to `<body>` — if you clicked a sidebar link that's
still sitting there, leave it alone. Use `preventScroll` to avoid
conflicts with `useScrollRestoration` on back/forward.

Side modal forms get their own routes, so the announcer has to know that
a form opening on top of a page isn't a page change. It keys off
`titleOnly` crumbs, which already mark exactly those routes (had to fix
`ip-pool-edit` and `subnet-pool-edit`, which were using `makeCrumb`).
Detecting the open dialog in the DOM instead seemed simpler, but it ran
into races.
StrictMode runs mount effects twice in dev, so a boolean guard was consumed
by the first run and the second run announced the initial page load and
focused the heading. Tracking the last location seen skips both runs.
The route announcer no longer sets tabIndex and outline-none on the h1 at
runtime; the RFD, login and error page headings declare them in JSX so a
re-render cannot drop them.

The live region is polite (role=status) instead of an assertive alert, so it
queues behind the focus announcement rather than racing it.

The modal and discussion dialog content wrappers are divs instead of main,
leaving one main landmark per page.

The Search e2e scrollY assertion polls instead of checking once, matching the
sibling test.
@notpeter

notpeter commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

I fixed conflicts and merged main and took a stab at addressing some issues identified by Claude. I'd love to give this enough love to get it over the line. Thanks for kicking it off @david-crespo.

@david-crespo

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread app/routes/rfd.$slug.tsx
Comment on lines +250 to +253
<h1
tabIndex={-1}
className="text-sans-2xl text-raise 600:pr-10 800:text-sans-3xl 1200:w-[calc(100%-var(--toc-width))] 1200:pr-16 w-full pr-4 text-balance outline-none print:pr-0 print:text-center"
>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Screen-reader users moving between two RFDs (for example with browser Back) may not get a focus move to the new page's heading. Focus stays on the old title. The h1 is not remounted on RFD-to-RFD navigation because Rfd and its <h1> are reused for /rfd/A → /rfd/B. When it already has focus, focus() in RouteAnnouncer.tsx:82 does nothing and fires no focus event. Fix: give the h1 a per-page key, such as key={number} or key={pathname}, so a new node is focused on every RFD nav. This makes the remount claim in RouteAnnouncer.tsx true for the RFD route.

Why this was flagged

The RouteAnnouncer comment at app/components/RouteAnnouncer.tsx:67-72 says the h1 is preferred over

because it "remounts on every page change". It adds that refocusing an already-focused element "fires no event, so the VO cursor would never move". For /rfd/A → /rfd/B, React Router renders the same Rfd route component in the same position. The

at app/routes/rfd.$slug.tsx:250 has no key, so React keeps the same DOM node and only changes its text. Here is a keyboard-user trigger. Client-navigate to RFD A; the announcer focuses its h1. Then from RFD A go to RFD B, for example via the Back/Forward keyboard shortcut, which leaves DOM focus where it was. When the announcer runs (main?.querySelector('h1') ?? main)?.focus({ preventScroll: true }) at RouteAnnouncer.tsx:82, the h1 is already document.activeElement, so no focus event fires. The new heading is never read through focus, which is the same failure the comment says choosing the h1 avoids. The keyed Header remounts, but that key does not reach the h1.

Verification: Trigger: a client-side RFD-to-RFD navigation while DOM focus is still on the h1. The <h1 tabIndex={-1}> (app/routes/rfd.$slug.tsx:250-255) has no key, so React keeps the same h1 DOM node. At RouteAnnouncer.tsx:82, focusing the element that already has focus does nothing and fires no focus event. The new e2e test only covers index to RFD. The base had no focus management at all.

Comment thread app/root.tsx
Comment on lines +160 to +161
{/* In Layout, not App, so error pages are announced too */}
<RouteAnnouncer />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Screen reader users who client-navigate into or out of an error page (e.g. a 404) will likely hear nothing. The live region is created and filled in the same commit. Layout is a plain component rendered separately by App and ErrorBoundary. Switching between them remounts the announcer <p>, and its effect sets textContent straight away. Screen readers generally ignore text written into a live region that has just been added to the DOM. Fix: keep the announcer mounted across the switch, e.g. make Layout the route-module export function Layout, so both App and ErrorBoundary render inside one persistent instance.

Why this was flagged

Trigger: a client-side nav where the root switches between App (root.tsx:172) and ErrorBoundary (root.tsx:104). Examples are a link to a missing RFD that throws a 404, or going back out of the error page. Each one renders its own <Layout> (root.tsx:105, 173), and Layout is a local const (root.tsx:125), not React Router's Layout export. React therefore unmounts the old RouteAnnouncer and mounts a new one. The module-level lastLocation (RouteAnnouncer.tsx:31) was added because of this remount. The new <p aria-live="polite"> is inserted and gets its text in the same effect (RouteAnnouncer.tsx:51-53). VoiceOver and NVDA generally only announce changes to a live region that was already in the accessibility tree. So the announcement the comment at root.tsx:160 promises for error pages is very likely silent. Normal page-to-page navs inside App work, because the <p> persists there.

Verification: nit. ErrorBoundary (root.tsx:104-117) and App (root.tsx:172+) each render their own <Layout>, so switching between them remounts <RouteAnnouncer />, and its effect fills the new live region in the same commit. Focus still moves to the new h1, so only the title announcement is lost. The base had no announcer at all, so nothing regresses.

// doesn't focus links on click, so after a link click focus is on the link
// in Firefox but on the body in Safari), and mid-navigation the outgoing
// page's #content can still be in the document alongside the new one.
if (pathname === '/' || hash) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Screen reader users who client-navigate to an error page at "/" or at a URL with a hash get no focus move. The error h1 was given tabIndex={-1} for exactly this case. The skip at RouteAnnouncer.tsx:65 treats pathname === '/' || hash as meaning the destination manages its own focus. That is only true when the index page or the target anchor actually rendered. Fix: base the skip on what rendered, not the URL. For example, mark the index <main> with a data attribute and skip only when it is present. Skip the hash case only when document.getElementById(hash.slice(1)) exists. This also covers the root ErrorBoundary at both kinds of URL.

Why this was flagged

The trigger is a client-side nav that ends in the root ErrorBoundary (app/root.tsx:93) at "/" or at a URL with a fragment. Example 1: the root loader rethrows a network or 5xx error from fetchRfds through logoutOnAuthError (app/services/auth.server.ts:187) while the user clicks "Back to index". The root revalidates because the pathname changed (root.tsx:83). Example 2: a search result links to /rfd/<n>#section for an RFD that now 404s. The ErrorBoundary remounts the whole tree, so the clicked link is gone and focus falls to . RouteAnnouncer.tsx:65 returns early in both cases. The focus target added for error pages (<h1 tabIndex={-1}> at root.tsx:112) is never focused, and the user stays at the top of the document with nothing read. Every other error-page URL does get its h1 focused, so this is a gap in the new behaviour. Its premise fails here: the index never mounted, so its filter-input autofocus never ran, and there is no anchor for the hash to point at.

Verification: The trigger is a client-side navigation that ends in the root ErrorBoundary while the URL is "/" or carries a fragment. RouteAnnouncer.tsx:65 returns early on if (pathname === '/' || hash) return based only on the URL, before the focus code at lines 81-82. This is not a regression against the base, which had no route focus management at all.

Comment thread app/routes/login.tsx
Comment on lines +154 to +156
<h1 tabIndex={-1} className="text-sans-2xl text-accent mb-4 outline-none">
Email sent
</h1>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: pre-existing: Screen reader users who send a login link still hear nothing. Focus falls to the body because the "Email sent" heading is never focused. The new tabIndex={-1} assumes the route announcer focuses this h1, but the redirect to /login?email=sent only changes the query string. RouteAnnouncer keys on pathname + hash and returns early. Fix: have Login focus its own h1 whenever the email/sent view changes after mount, e.g. a useEffect on [showEmailForm, emailSuccess] that skips the first run. Keep the announcer's search-insensitive key, which the index filter URLs (/?author=…) rely on.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

A user on /login clicks "Continue with Email" and submits the <Form action="/login" method="post"> (login.tsx:165). The magic-link strategy's pendingPath: '/login?email=sent' (app/services/auth.server.ts:128) redirects client-side to the same route. Login stays mounted, so showEmailForm stays true and emailSuccess flips to true. The submit button unmounts and focus falls to . RouteAnnouncer (app/components/RouteAnnouncer.tsx:41-44) computes pathname + hash = '/login' for both locations, so changed is false. It neither writes the live region nor focuses #content h1. The h1s at login.tsx:154 and :162 were given tabIndex={-1}/outline-none on the premise (comment at login.tsx:124) that the route announcer focuses them. No path does that, so the tabIndex is dead. The "Email sent" confirmation goes unannounced, the same as on the base branch. Toggling via "Continue with Email" and "Cancel" also unmounts the focused button without any route change.

Verification: The trigger is a screen reader user submitting the email form on /login. app/services/auth.server.ts:128 sets pendingPath: '/login?email=sent'. RouteAnnouncer.tsx builds its key from const location = pathname + hash. Both locations are '/login', so it neither writes to the live region nor focuses #content h1. This is an accessibility gap, not a regression.

This branch was successfully deployed

1 active deployment
Preview — 986504d8 Deployed Nov 6, 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