Skip to content

Commit 3b7ca62

Browse files
committed
Check flashing preferences before allowing autoplaying looping videos.
Flashing preferences are a guardian accessibility setting. The value is held in local storage.
1 parent 5d10f9a commit 3b7ca62

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

dotcom-rendering/src/components/LoopVideo.importable.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/react';
2-
import { log } from '@guardian/libs';
2+
import { log, storage } from '@guardian/libs';
33
import { SvgAudio, SvgAudioMute } from '@guardian/source/react-components';
44
import { useEffect, useRef, useState } from 'react';
55
import { getZIndex } from '../lib/getZIndex';
@@ -80,8 +80,8 @@ export const LoopVideo = ({
8080
/**
8181
* Setup.
8282
*
83-
* Register the users motion preferences.
84-
* Creates event listeners to control playback when there are multiple videos.
83+
* 1. Register the user's motion preferences.
84+
* 2. Creates event listeners to control playback when there are multiple videos.
8585
*/
8686
useEffect(() => {
8787
/**
@@ -90,7 +90,18 @@ export const LoopVideo = ({
9090
const userPrefersReducedMotion = window.matchMedia(
9191
'(prefers-reduced-motion: reduce)',
9292
).matches;
93-
setIsAutoplayAllowed(!userPrefersReducedMotion);
93+
94+
const flashingPreferences = storage.local.get(
95+
'gu.prefs.accessibility.flashing-elements',
96+
);
97+
98+
/**
99+
* `flashingPreference` is `null` if no preference exists and explicitly
100+
* `false` when the reader has said they don't want flashing
101+
*/
102+
setIsAutoplayAllowed(
103+
!userPrefersReducedMotion || flashingPreferences === null,
104+
);
94105

95106
/**
96107
* Mutes the current video when another video is unmuted
@@ -110,7 +121,7 @@ export const LoopVideo = ({
110121
};
111122

112123
/**
113-
* Mute the current video when a Youtube video is played
124+
* Mute the current video when a YouTube video is played
114125
* Triggered by the CustomEvent in YoutubeAtomPlayer.
115126
*/
116127
const handleCustomPlayYoutubeEvent = () => {

0 commit comments

Comments
 (0)