Skip to content

Commit deb2bfc

Browse files
authored
Check flashing preferences before allowing autoplaying looping videos. (#14196)
Flashing preferences are a guardian accessibility setting. The value is held in local storage. If the user has explicitly indicated they do not want flashing, we disable looping videos.
1 parent 38959a1 commit deb2bfc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 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 { useCallback, useEffect, useRef, useState } from 'react';
55
import { submitClickComponentEvent } from '../client/ophan/ophan';
@@ -140,8 +140,8 @@ export const LoopVideo = ({
140140
/**
141141
* Setup.
142142
*
143-
* Register the users motion preferences.
144-
* Creates event listeners to control playback when there are multiple videos.
143+
* 1. Register the user's motion preferences.
144+
* 2. Creates event listeners to control playback when there are multiple videos.
145145
*/
146146
useEffect(() => {
147147
/**
@@ -150,7 +150,19 @@ export const LoopVideo = ({
150150
const userPrefersReducedMotion = window.matchMedia(
151151
'(prefers-reduced-motion: reduce)',
152152
).matches;
153-
setIsAutoplayAllowed(!userPrefersReducedMotion);
153+
154+
/**
155+
* The user indicates a preference for no flashing elements.
156+
* `flashingPreference` is `null` if no preference exists and
157+
* explicitly `false` when the reader has said they don't want flashing.
158+
*/
159+
const flashingPreferences = storage.local.get(
160+
'gu.prefs.accessibility.flashing-elements',
161+
);
162+
163+
setIsAutoplayAllowed(
164+
!userPrefersReducedMotion && flashingPreferences !== false,
165+
);
154166

155167
/**
156168
* Mutes the current video when another video is unmuted
@@ -170,7 +182,7 @@ export const LoopVideo = ({
170182
};
171183

172184
/**
173-
* Mute the current video when a Youtube video is played
185+
* Mute the current video when a YouTube video is played
174186
* Triggered by the CustomEvent in YoutubeAtomPlayer.
175187
*/
176188
const handleCustomPlayYoutubeEvent = () => {

0 commit comments

Comments
 (0)