744 B24 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8let prefersReducedMotionValue = false;
9
10try {
11 const prefersReducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
12 prefersReducedMotionQuery.addEventListener('change', () => {
13 prefersReducedMotionValue = prefersReducedMotionQuery.matches;
14 });
15 prefersReducedMotionValue = prefersReducedMotionQuery.matches;
16} catch (_e) {
17 // testing-library does not define "window.matchMedia".
18}
19
20/** Returns `true` if the user wants reduced animation. */
21export function prefersReducedMotion() {
22 return prefersReducedMotionValue;
23}
24