Skip to content

fix(ui): announce form errors, manage focus, respect reduced motion - #126

Merged
Ardnived merged 5 commits into
mainfrom
fix/a11y-forms-motion
Aug 8, 2026
Merged

Ardnived merged 5 commits into
mainfrom
fix/a11y-forms-motion

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Three accessibility groups from .claude/reports/RELEASE_READINESS.md §5.

  • A failed submit is no longer silent. FormField's error span is role="alert", which is what tells a viewer about the invalid fields they are not focused on, and focus now reaches the first invalid field in every case.
  • prefers-reduced-motion is honoured, through one seam per animation technology rather than one per component.
  • Six focus/label findings closed: peek strips, Chip's close button, the Spinner's SR text, the contact popover, and Mapbox's GeolocateControl.

Changes worth explaining

The ticket was wrong about two things, both verified rather than assumed.

Focus already worked — for two of the three fields. react-hook-form's shouldFocusError defaults to true and was already focusing the register()ed inputs. The real gap was the starting-date field: a Controller wrapping RadioGroup, which is not forwardRef and so swallowed field.ref. RHF stores undefined for such a field and skips it in silence, so a submit with no date chosen moved nothing and said nothing. Fixed at the atom; no setFocus call was added, because the library's own default now reaches every field and a second implementation could only drift.

The map camera needed nothing. mapbox-gl already handles reduced motion in the same three calls use-mapbox.ts makes — flyTo short-circuits to jumpTo, easeTo zeroes its duration, fitBounds reaches one of them — gated on respectPrefersReducedMotion (defaults on) and on a live .matches read. flyTo's branch preserves padding/retainPadding through the jump, and fitBoundsOptions contributes only maxZoom + padding, so nothing of ours is lost. A hand-rolled branch would have been dead code that drifts from the one that actually runs. The hook gained a comment recording the verification and the two ways to break it (respectPrefersReducedMotion: false, or essential: true on a camera call).

Announcement had to be opt-outable. ReportIssueForm uses mode: 'onChange', so an unconditional alert would fire on the first character of an email address. It also gates Send on isValid, so it has no failed submit to announce. Both its fields pass announceError={false}. The default is on, so a future form's failure mode is over-announcement (audible, fixable) rather than silence (invisible).

Reduced motion is three seams, not three components — framer's MotionConfig, a CSS media block for vaul (which animates in CSS), and mapbox-gl's own check. MotionConfig is driven by usePrefersReducedMotion() rather than framer's reducedMotion="user", which reads matchMedia once at mount; "user" would have disagreed with the other two seams for the rest of any session in which the viewer flipped the setting. The hook's own doc comment had flagged this and left the decision to whoever landed it.

Verification

  • Lint ✓ · Typecheck ✓ · Unit lane ✓ (768 tests, 22 new) · Build ✓ · assert:css ✓ · pnpm size ✓ · ladle:build ✓

Review passes: 3 of 5 complete. /simplify's four cleanup agents (reuse, simplification, efficiency, altitude) all completed and were triaged. The /code-review and /security-review passes did not run — security was correctly skipped (no risky paths: no config/api, Widget.tsx, HTML sinks, deps or env in the diff), but /code-review never ran because the session was interrupted twice. Worth a reviewer's attention accordingly.

The efficiency pass caught a regression this branch introduced: the strip-name lookups were reading their caches through useQuery({ enabled: false }), copied from DrawerChrome. That is right there (it mounts only during loading/error) and wrong in DrawerStack, which is mounted for the whole session — React Query counts gcTime from the last observer unmounting, so the region tree and one titles Map per language would never be collected. Now read via getQueryData.

Manual accessibility checks for a browser

Not run here — this wave's browser was owned by a sibling ticket. In rough priority:

  1. Reduced motion end-to-end. With prefers-reduced-motion: reduce set at the OS level: drawers should appear/dismiss instantly (no slide), peek strips should not travel, and map navigation should jump rather than fly. Then toggle the OS setting mid-session — all three should follow without a reload. That liveness is the whole reason for the custom hook, and it is the one thing no unit test covers.
  2. A drawer must still close under reduced motion. The CSS block relies on Radix's Presence reading animationName: none as "already finished". Open and dismiss a nested drawer a few times and confirm nothing is left mounted or stranded half-open.
  3. Screen reader on the registration form (VoiceOver/NVDA). Submit empty: confirm focus lands on the starting-date radios, that the error is spoken, and that the other invalid fields are announced too. Then type into a field and confirm nothing re-announces per keystroke.
  4. Report-issue form, same reader — confirm the opposite: typing an email should not interrupt.
  5. Tab through a 2–3 deep drawer stack — every peek strip should show a visible ring, and the reader should say "Back to United Kingdom" / "Back to London" rather than three identical "Back"s.
  6. GeolocateControl in a non-English locale — hover/focus the control on first load and confirm the tooltip is localized. Known limitation: a mid-session language switch will not relabel it (construction-only, same as the language prop beside it).
  7. Chip close ring — tab to an active-filter pill's × while the pointer rests on the same chip; the ring should be visible.

WCAG status against the readiness report's four AA failures

# Failure Status
1 Autoplaying carousel, no pause (2.2.2) Closed — by sibling #104, not here
2 No lang on the embedded subtree (3.1.2) Still open — Widget.tsx, not in this ticket's scope
3 Per-field errors not announced (4.1.3 / 3.3.1) Closed here
4 No prefers-reduced-motion (2.3.3) Closed here

Plus six of §5's should-fix items. Still open from that list: landmarks/skip link, and no automated a11y checks (no axe in CI or Ladle).

Notes for reviewer

Deliberately not done, each with a reason:

  • stripLabel duplicates DrawerChrome's title switch (flagged by the reuse and altitude passes, and a fair hit — drift between them would produce exactly the mismatched-name class of bug this PR fixes). Merging them means touching views/fallbacks.tsx, reconciling a second i18n namespace and its defaultValue policy. Left as a follow-up rather than restructuring a critical error path with siblings in flight.
  • announceError as a per-call-site boolean rather than derived from the form's validation mode via context. The current shape is fail-safe (default on); the deeper fix is a larger redesign.
  • The vaul reduced-motion block lives in vaul.css, not globals.css, despite that file being vendored. It is at the foot, below a divider, and the file header's refresh instructions were updated to say so.
  • RadioGroup's error is announced but not aria-describedby-wired — the composite field has no single id, and inventing one gives a <label for> pointing at nothing.

Sibling coordination: edits here are confined to RegistrationForm's submit/focus logic, clear of #105's confirmation-screen region. Three additive common locale keys across all ten locales.

Closes #102

🤖 Generated with Claude Code

Ardnived and others added 4 commits August 7, 2026 10:29
MotionConfig covers every motion.* in the tree (the peek strips, the
drawer cross-fade); the vaul drawers animate in CSS and so need a CSS
switch of their own.

Both are driven by a LIVE read of the preference — MotionConfig's own
`reducedMotion="user"` reads matchMedia once at mount, which would let a
viewer who flips the setting mid-session keep the motion, and disagree
with the media query the drawers are on.

Refs #102

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A failed submit was silent. Field errors carried the aria-describedby id
but no live semantics, so nothing was announced for any field a reader
was not already standing on (WCAG 4.1.3 / 3.3.1).

FormField's error span is now role="alert" by default. It cannot chatter
per keystroke, because it is mounted only while an error is set and the
registration form validates on submit; a live region speaks on mutation,
so re-validating an unchanged message says nothing. ReportIssueForm opts
out — it validates on every keystroke and gates Send on validity, so it
has no failed submit to announce, only interruptions to offer.

Focus already moved for the two register()ed inputs (react-hook-form's
default shouldFocusError). The gap was the starting-date RadioGroup: a
Controller field RHF was never handed a ref for, so a submit with no
date chosen moved nothing and said nothing. RadioGroup now forwards a
ref to its first radio.

Refs #102

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…name

Four findings from the readiness review, all in the same register — a
control that works but cannot be seen or told apart.

Peek strips: each one was named "Back", so a three-deep stack offered
three identically-named buttons going to three different places. They
now name their destination from the caches the app has already filled
(cache-only, like DrawerChrome — a miss costs the name, not the strip),
and draw the app's focus ring, which they had none of.

Chip's close button showed only an opacity lift on focus — which is also
what hover does, so on a chip under the pointer it showed nothing.

Spinner's screen-reader text was the app's one hard-coded English
string. It is a prop now, defaulting to English: the atom cannot call
t() because it renders in Suspense fallbacks that run before the
bundles load, where t() returns the raw key.

The contact popover portals out of the tree with no focus management, so
pressing Contact announced a dialog and then tabbed past it.

Also localizes Mapbox's GeolocateControl, the last English-only label.
Construction-only — react-map-gl does not reconcile `locale` — which is
the same limitation the `language` prop beside it already carries.

Refs #102

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The peek-strip names were reading their two caches through
`useQuery({ enabled: false })`, copying DrawerChrome. That is right for
DrawerChrome, which mounts only while a view is loading or has thrown,
and wrong here: DrawerStack is mounted for the whole session, and React
Query counts gcTime from the last observer unmounting — so the region
tree and one titles Map per language visited would never be collected.
Reads them with getQueryData instead, which keeps the cache-only
contract and drops the subscription.

Also: a Map rather than a linear scan of every region in the world, per
strip, per render; `t` off useLocale at three call sites (it already
holds one for the default namespace and returns it to avoid exactly this
duplicate subscription); and two comments that described APIs this repo
does not use.

Refs #102

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: badd715
Status: ✅  Deploy successful!
Preview URL: https://fa521e6d.sahajatlas.pages.dev
Branch Preview URL: https://fix-a11y-forms-motion.sahajatlas.pages.dev

View logs

@Ardnived

Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

CI: Dependency Audit is red, and it is not this branch

Everything else is green — Lint, Typecheck & Build, Smoke, and both Cloudflare Pages deploys.

Dependency Audit fails on 4 advisories published against the existing lockfile:

Severity Package Advisory
high image-size GHSA-w3rx-r6r6-pgpr, GHSA-5p2g-fcmc-qvqq
high nanoid GHSA-28wg-ghj8-5hjv, GHSA-2v37-7h3g-55p8

Not caused by this PR:

  • the diff contains no package.json and no pnpm-lock.yaml change (git diff --name-only origin/main...HEAD);
  • both are transitive dev-graph packages nothing here imports;
  • PR perf(list): bound the results list by DOM budget, not virtualization #125 fails the same check identically, so it is a repo-wide condition that appeared when the advisories were published, not a property of either branch.

Deliberately not fixed here. The check's own message offers two routes — bump the dependency, or add the ids to scripts/audit-baseline.json "with the ticket that owns it". Bumping touches the lockfile, which would conflict with every sibling branch in flight this wave; baselining is a security-debt decision that should be recorded against a ticket that owns it, not slipped into an accessibility PR. It wants its own ticket.

Ardnived added a commit that referenced this pull request Aug 8, 2026
Four high advisories published 2026-08-07 against the existing lockfile (image-size x2, nanoid x2) turned the audit gate red on every open PR, none of which touch either package. Both are verified absent from the shipped bundle by build + grep — payload is types-only so image-size never ships, postcss is build-time, and the one 'nanoid' string in dist/ is zod's .nanoid() validator name. image-size has no published fix; nanoid's is held back by postcss's own pin and arrives free under #101. Baselined against #101 with per-entry reasoning.

Unblocks #123, #125, #126, #127.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: badd715
Status: ✅  Deploy successful!
Preview URL: https://a1a90f6a.sahajatlas-design.pages.dev
Branch Preview URL: https://fix-a11y-forms-motion.sahajatlas-design.pages.dev

View logs

@Ardnived
Ardnived merged commit c82c595 into main Aug 8, 2026
5 checks passed
@Ardnived
Ardnived deleted the fix/a11y-forms-motion branch August 8, 2026 00:10
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.

fix(ui): announce form errors, manage focus, respect reduced motion

1 participant