fix(a11y): honour reduced-motion on the thinking timer + name the send button#5589
Open
BrunooMoniz wants to merge 1 commit into
Open
fix(a11y): honour reduced-motion on the thinking timer + name the send button#5589BrunooMoniz wants to merge 1 commit into
BrunooMoniz wants to merge 1 commit into
Conversation
…d button The live "Thinking..." elapsed timer drove itself with a self-perpetuating requestAnimationFrame that rewrote the header text ~60x/second for the whole thinking duration and ignored prefers-reduced-motion. Replace it with a matchMedia-gated setInterval (reduced-motion => 1Hz whole seconds; coarse pointer => 250ms; fine pointer => 100ms). The tick self-clears when the timer element is gone, and the explicit teardown sites clear the interval instead of cancelling an animation frame. No visual change at the default motion setting. The icon-only send/stop button keeps its accessible name in `title`, synced per mode (Send message / Stop generation / Queue message), but `title` alone is not reliably announced by iOS VoiceOver on a <button>, so a screen-reader user can miss "Stop generation" while a response streams. Mirror the live title into aria-label (which IS announced) with a cheap attribute-filtered MutationObserver, so the accessible name always tracks the action from a single source of truth. Adds tests/test_chat_a11y_js.py, which lifts the real timer and aria helpers out of chat.js and executes them under node with a stubbed matchMedia and MutationObserver, asserting the reduced-motion cadence and the mirrored name.
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
Two small, related accessibility fixes in the chat UI, both in
static/js/chat.js. First, the live "Thinking…" elapsed timer drove itself with a self-perpetuatingrequestAnimationFramethat rewrote the header text roughly 60 times a second — a tenths-of-a-second readout — for the entire thinking duration, and it ignoredprefers-reduced-motion, so a user who asked for reduced motion still got a rapidly repainting counter. This PR replaces that loop with amatchMedia-gatedsetInterval: under reduced motion the timer shows whole seconds at 1Hz, a coarse pointer ticks at 250ms, and a fine pointer at 100ms (a tenths readout can't change faster than 100ms anyway). The tick self-clears once the timer element is gone, matching the old loop's self-terminating behaviour, and the three explicit teardown sites clear the interval instead of cancelling an animation frame. At the default motion setting the readout is visually identical. Second, the icon-only send/stop button keeps its accessible name only intitle, synced per mode (Send message / Stop generation / Queue message), buttitlealone is not reliably announced by iOS VoiceOver on a<button>, so a screen-reader user can miss "Stop generation" while a response streams. The fix mirrors the livetitleintoaria-label(which is announced) with a cheap attribute-filteredMutationObserver, from the same single source of truth, seeding the label once at wire time so it is correct before any mode switch.Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #5588
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
Steps a reviewer can reproduce (full app):
A. Reduced-motion on the thinking timer
docker compose up -d --build, open the chat.reduce(or set it at the OS level).dev: the timer repaints a tenths counter many times a second regardless of the preference. With this branch: under reduced motion it updates once a second in whole seconds; with motion allowed it is unchanged.B. Accessible name on the send/stop button
dev: there is noaria-label, so the name is empty / unlabelled. With this branch: the name reads "Send message" when idle and "Stop generation" while streaming, and tracks the button'stitleas the mode changes.What was verified for this change:
node --check static/js/chat.js— passes.python -m pytest tests/test_chat_a11y_js.py— 6 passed (reduced-motion cadence, fine/coarse-pointer cadence, norequestAnimationFrame, self-clearing tick, and the mirrored accessible name).python -m pytest— full suite green: 4625 passed, 4 skipped, 0 failed (baseline on thisdevcheckout without the change: 4619 passed, 4 skipped — i.e. +6 from the new test, no regressions).Files changed:
static/js/chat.js— the live thinking timer now runs on amatchMedia-gatedsetIntervalinstead of arequestAnimationFrameloop (three teardown sites switch toclearInterval), andinit()mirrors the send button'stitleintoaria-labelvia an attribute-filteredMutationObserver.tests/test_chat_a11y_js.py— new.chat.jspulls in browser globals and can't be imported under node, so the test lifts the real timer and aria helpers out of the source and runs them under node with a stubbedmatchMedia/MutationObserver, asserting the reduced-motion cadence and the mirrored accessible name.Visual / UI changes — REQUIRED if you touched anything that renders
Anything that changes what the UI looks like — buttons, icons, padding, colors, fonts, spacing, layout, CSS, HTML, SVG, or any
static/js/module that draws to the DOM — needs all of the following. PRs that change rendering without these WILL be closed.aria-labelmirror is screen-reader-only. There is nothing to screenshot — see How to Test for reproduction with reduced-motion emulated and with the DevTools accessibility tree, and the node-driven test for an automated proof. No colours, fonts, spacing, components, or markup were added or changed.--red,--fg,--bg,--card,--border, etc.) — do not introduce new color values, font sizes, or spacing units.static/index.html) or plain text.Fira Code) for primary UI text. Don't override.Screenshots / clips
No screenshots — the change is non-visual (behavioural reduced-motion timing and a screen-reader-only
aria-label). Reproduction and an automated node-driven test are described under How to Test above.