addons/isl/src/mediaQuery.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318let prefersReducedMotionValue = false;
b69ab319
b69ab3110try {
b69ab3111 const prefersReducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
b69ab3112 prefersReducedMotionQuery.addEventListener('change', () => {
b69ab3113 prefersReducedMotionValue = prefersReducedMotionQuery.matches;
b69ab3114 });
b69ab3115 prefersReducedMotionValue = prefersReducedMotionQuery.matches;
b69ab3116} catch (_e) {
b69ab3117 // testing-library does not define "window.matchMedia".
b69ab3118}
b69ab3119
b69ab3120/** Returns `true` if the user wants reduced animation. */
b69ab3121export function prefersReducedMotion() {
b69ab3122 return prefersReducedMotionValue;
b69ab3123}