Skip to content

Commit 563d46d

Browse files
madster456N2D4
andauthored
prefers-reduced-motion added to top waves (#799)
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> enabled prefers-reduced-motion on the waves.tsx file for top banner. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Adds `prefers-reduced-motion` support to `Waves` component in `waves.tsx`, disabling wave rendering if motion reduction is preferred. > > - **Behavior**: > - Adds `prefers-reduced-motion` detection in `Waves` component in `waves.tsx`. > - Uses `useState` and `useEffect` to track and respond to `prefers-reduced-motion` media query. > - If `prefers-reduced-motion` is true, the component returns `null`, preventing wave rendering. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup> for 5db322e. You can [customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * The wave animation is now automatically disabled for users who have enabled reduced motion preferences in their system settings, improving accessibility. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
1 parent ffb720d commit 563d46d

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

docs/src/components/layouts/api/waves.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
'use client';
55

6-
import React, { CSSProperties, useEffect, useRef } from "react";
6+
import React, { CSSProperties, useEffect, useRef, useState } from "react";
77

88
class Grad {
99
x: number;
@@ -207,6 +207,28 @@ const Waves: React.FC<WavesProps> = ({
207207

208208
const frameIdRef = useRef<number | null>(null);
209209

210+
// Add prefers-reduced-motion detection
211+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
212+
213+
// Check for prefers-reduced-motion preference
214+
useEffect(() => {
215+
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
216+
217+
// Set initial value
218+
setPrefersReducedMotion(mediaQuery.matches);
219+
220+
// Listen for changes
221+
const handleChange = (e: MediaQueryListEvent) => {
222+
setPrefersReducedMotion(e.matches);
223+
};
224+
225+
mediaQuery.addEventListener('change', handleChange);
226+
227+
return () => {
228+
mediaQuery.removeEventListener('change', handleChange);
229+
};
230+
}, []);
231+
210232
useEffect(() => {
211233
configRef.current = {
212234
lineColor,
@@ -422,6 +444,11 @@ const Waves: React.FC<WavesProps> = ({
422444
};
423445
}, []);
424446

447+
// If user prefers reduced motion, don't render the waves at all
448+
if (prefersReducedMotion) {
449+
return null;
450+
}
451+
425452
return (
426453
<div
427454
ref={containerRef}

0 commit comments

Comments
 (0)