Files
HealthLog/src/lib/motion.ts
T
Marc-André Bombeck d9fe0e5487 fix(motion): respect prefers-reduced-motion across smooth scrolls
Programmatic `scrollIntoView` / `scrollTo` calls in the settings shell,
admin shell, and coach message thread ignored the user's reduced-motion
preference — a WCAG 2.3.3 violation. Add a single `scrollBehaviorForUser`
helper in `src/lib/motion.ts` that returns `"auto"` when SSR or when
`(prefers-reduced-motion: reduce)` matches, and `"smooth"` otherwise.
Wire it through the three call-sites; tests cover all three branches.
2026-05-21 21:45:58 +02:00

14 lines
612 B
TypeScript

// v1.4.43 W5-H5 — single source of truth for `behavior` on the four
// programmatic `scrollIntoView` / `scrollTo` call-sites in the app.
// `prefers-reduced-motion: reduce` users were previously animated against
// their OS-level preference, which is a WCAG 2.3.3 violation. The helper
// returns `"auto"` whenever a window is unavailable (SSR) or when the
// reduced-motion media query matches.
export function scrollBehaviorForUser(): ScrollBehavior {
if (typeof window === "undefined") return "auto";
return window.matchMedia("(prefers-reduced-motion: reduce)").matches
? "auto"
: "smooth";
}