Skip to content

Commit 2705a3c

Browse files
Merge pull request #106 from DevelopmentFinanceObservatory/feature/accessiblity-fixes
Feature/accessiblity fixes
2 parents c6436e3 + 60ae56b commit 2705a3c

9 files changed

Lines changed: 81 additions & 7 deletions

File tree

‎src/components/atoms/Spinner/Spinner.module.scss‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@
1717
rotate: 360deg;
1818
}
1919
}
20+
21+
@media (prefers-reduced-motion: reduce) {
22+
// A frozen ring reads as a broken circle, so the spinner stays on, slowed.
23+
.spinner {
24+
animation-duration: 2.4s;
25+
}
26+
}

‎src/components/organisms/CreateCanvas/ShowcaseCards.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ const ShowcaseCards = ({ grid }: { grid: Grid }) => {
240240
// eslint-disable-next-line react-hooks/exhaustive-deps
241241
}, [reducedMotion, phone]);
242242

243+
// Pure decoration: the cards keep their real buttons (the source line,
244+
// the left-out line), so `inert` takes the whole layer out of the tab
245+
// order and hit testing; aria-hidden covers readers on older browsers.
243246
return (
244-
<div className={styles.layer} aria-hidden="true">
247+
<div className={styles.layer} aria-hidden="true" inert>
245248
{tiles.map(({ key, col, row, w, h, card, leaving }) => {
246249
const widget = widgets[card]!;
247250
const title = widget.kind === 'key_number' ? widget.label : widget.title;

‎src/components/organisms/DataSearch/DataSearch.module.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ $table-head-cover: rem(48);
490490
}
491491
}
492492

493+
@media (prefers-reduced-motion: reduce) {
494+
.slotUpdating {
495+
animation: none;
496+
}
497+
}
498+
493499
// Sentence slots: yellow, underlined, clickable. The underline and the
494500
// hover fill are two stacked BACKGROUND layers (not a pseudo-element): a
495501
// slot can be an inline span that wraps across lines, and with

‎src/components/organisms/DownloadDataset/DownloadDataset.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Button from '@/components/atoms/Button/Button';
1010
import DataPrompt from '@/components/molecules/DataPrompt/DataPrompt';
1111
import SectionHeading from '@/components/molecules/SectionHeading/SectionHeading';
1212
import StatTiles from '@/components/molecules/StatTiles/StatTiles';
13+
import { usePrefersReducedMotion } from '@/hooks/usePrefersReducedMotion';
1314
import { revealIndex, useReveal } from '@/hooks/useReveal';
1415
import {
1516
catalogueChips,
@@ -27,14 +28,17 @@ const DownloadDataset = ({ catalogue }: { catalogue: SearchCatalogue | null }) =
2728
const sectionRef = useReveal<HTMLElement>();
2829
const canvasRef = useRef<HTMLCanvasElement>(null);
2930
const tiles = catalogueTiles(catalogue);
31+
const reducedMotion = usePrefersReducedMotion();
3032

33+
// The net reads the motion preference itself when it starts (a still
34+
// frame, or the live field); it restarts whenever the reader flips it.
3135
useEffect(() => {
3236
if (!sectionRef.current || !canvasRef.current) {
3337
return;
3438
}
3539

3640
return startDatasetNet(sectionRef.current, canvasRef.current);
37-
}, [sectionRef]);
41+
}, [sectionRef, reducedMotion]);
3842

3943
return (
4044
<section

‎src/components/organisms/DownloadDataset/dataset-net.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,19 @@ export function startDatasetNet(
320320
cursor.ty *= sy;
321321
}
322322

323-
const resizeObserver = new ResizeObserver(resize);
323+
const reducedMotion =
324+
typeof window.matchMedia === 'function' &&
325+
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
326+
327+
const resizeObserver = new ResizeObserver(() => {
328+
resize();
329+
330+
// No loop runs under reduced motion, so the still frame is redrawn
331+
// by hand whenever the section changes size.
332+
if (reducedMotion) {
333+
draw();
334+
}
335+
});
324336

325337
resizeObserver.observe(innerEl);
326338

@@ -403,7 +415,13 @@ export function startDatasetNet(
403415
frame = requestAnimationFrame(loop);
404416
}
405417

406-
frame = requestAnimationFrame(loop);
418+
// Under reduced motion the field is one still frame: the squares sit at
419+
// their home spots and nothing drifts.
420+
if (reducedMotion) {
421+
draw();
422+
} else {
423+
frame = requestAnimationFrame(loop);
424+
}
407425

408426
return () => {
409427
cancelAnimationFrame(frame);

‎src/components/organisms/Hero/Hero.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import styles from './Hero.module.scss';
77
import { startHeroNet } from './hero-net';
88

99
import Icon from '@/components/atoms/Icon/Icon';
10+
import { usePrefersReducedMotion } from '@/hooks/usePrefersReducedMotion';
1011
import { revealIndex, useReveal } from '@/hooks/useReveal';
1112
import LogoSignature from '@/assets/svg/logo-signature.svg';
1213
import WorldMap from '@/components/atoms/WorldMap/WorldMap';
@@ -53,6 +54,7 @@ const Hero = ({
5354
const sectionRef = useReveal<HTMLElement>(0);
5455
const innerRef = useRef<HTMLDivElement>(null);
5556
const canvasRef = useRef<HTMLCanvasElement>(null);
57+
const reducedMotion = usePrefersReducedMotion();
5658

5759
// One-shot arrow swap (mirrors Button): hover must rest a beat to start
5860
// it, and once started it always plays out — leaving doesn't cut it off.
@@ -114,8 +116,10 @@ const Hero = ({
114116
observer.disconnect();
115117
net.stop();
116118
};
119+
// The net reads the motion preference itself when it starts (a still
120+
// frame, or the live field); it restarts whenever the reader flips it.
117121
// eslint-disable-next-line react-hooks/exhaustive-deps -- sectionRef is stable (useReveal's ref)
118-
}, []);
122+
}, [reducedMotion]);
119123

120124
// One reveal GROUP for the whole hero: the observer watches the
121125
// full-viewport section (the telescoping panels start at scale 0 —

‎src/components/organisms/Hero/hero-net.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,15 @@ export function startHeroNet(
283283
});
284284
}
285285

286-
const resizeObserver = new ResizeObserver(resize);
286+
const resizeObserver = new ResizeObserver(() => {
287+
resize();
288+
289+
// No loop runs under reduced motion, so the still frame is redrawn
290+
// by hand whenever the panel changes size.
291+
if (reducedMotion) {
292+
draw();
293+
}
294+
});
287295
resizeObserver.observe(innerEl);
288296

289297
function update(now: number): void {
@@ -405,7 +413,13 @@ export function startHeroNet(
405413
frame = requestAnimationFrame(loop);
406414
}
407415

408-
frame = requestAnimationFrame(loop);
416+
// Under reduced motion the field is one still frame: the squares sit at
417+
// their home spots and nothing drifts, swirls or pours in.
418+
if (reducedMotion) {
419+
draw();
420+
} else {
421+
frame = requestAnimationFrame(loop);
422+
}
409423

410424
return {
411425
stop: () => {

‎src/components/organisms/Studio/workspace/ActivityLog.module.scss‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,14 @@
476476
opacity: 0.6;
477477
}
478478
}
479+
480+
@media (prefers-reduced-motion: reduce) {
481+
// The live dot sits still: no ping ring, no pulse on the running step.
482+
.live::after {
483+
display: none;
484+
}
485+
486+
.stepRunning::before {
487+
animation: none;
488+
}
489+
}

‎src/components/organisms/Studio/workspace/PlanLedger.module.scss‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@
242242
}
243243
}
244244

245+
@media (prefers-reduced-motion: reduce) {
246+
// A frozen ring reads as a broken circle, so the spinner stays on, slowed.
247+
.spin {
248+
animation-duration: 2.4s;
249+
}
250+
}
251+
245252
// The notice's live region, mounted empty, spanning the row.
246253
.live {
247254
grid-column: 1 / -1;

0 commit comments

Comments
 (0)