MCPcopy Create free account
hub / github.com/adobe/react-spectrum / reducedMotionCheck

Function reducedMotionCheck

packages/dev/docs/src/client.js:280–313  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

278
279// Disable autoplay for videos when the prefers-reduced-motion media query is enabled.
280function reducedMotionCheck(e) {
281 let videos = document.querySelectorAll('video[autoplay]');
282 if (e.matches) {
283 for (let v of videos) {
284 v.pause();
285 v.controls = true;
286 v.removeAttribute('tabindex');
287 v.onclick = undefined;
288 v.onkeydown = undefined;
289 }
290 } else {
291 for (let v of videos) {
292 let toggle = () => {
293 if (v.paused) {
294 v.play();
295 } else {
296 v.pause();
297 }
298 };
299 if (v.paused) {
300 v.play();
301 }
302 v.tabIndex = 0;
303 v.controls = false;
304 v.onclick = toggle;
305 v.onkeydown = e => {
306 if (e.key === ' ' || e.key === 'Enter') {
307 e.preventDefault();
308 toggle();
309 }
310 };
311 }
312 }
313}
314
315let prefersReducedMotion = matchMedia('(prefers-reduced-motion)');
316reducedMotionCheck(prefersReducedMotion);

Callers 1

client.jsFile · 0.85

Calls 3

pauseMethod · 0.80
removeAttributeMethod · 0.80
toggleFunction · 0.70

Tested by

no test coverage detected