From 7cb2c36ac954f9fb1a2cadad8b49bf35df08673f Mon Sep 17 00:00:00 2001 From: orangemug Date: Fri, 11 May 2018 09:32:57 +0100 Subject: [PATCH] Move accessibility checks into module. --- src/components/layers/CollapseReducedMotion.jsx | 9 ++------- src/libs/accessibility.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/libs/accessibility.js diff --git a/src/components/layers/CollapseReducedMotion.jsx b/src/components/layers/CollapseReducedMotion.jsx index 28bfa9b..6a1b64e 100644 --- a/src/components/layers/CollapseReducedMotion.jsx +++ b/src/components/layers/CollapseReducedMotion.jsx @@ -1,14 +1,9 @@ import React from 'react' import PropTypes from 'prop-types' import Collapse from 'react-collapse' -import lodash from 'lodash' +import accessibility from '../../libs/accessibility' -// Wait 3 seconds so when a user enables it they don't have to refresh the page. -const isReduceMotionEnabled = lodash.throttle(() => { - return window.matchMedia("(prefers-reduced-motion: reduce)").matches -}, 3000); - export default class CollapseReducedMotion extends React.Component { static propTypes = { isActive: PropTypes.bool.isRequired, @@ -16,7 +11,7 @@ export default class CollapseReducedMotion extends React.Component { } render() { - if (isReduceMotionEnabled()) { + if (accessibility.reducedMotionEnabled()) { return (
{this.props.children} diff --git a/src/libs/accessibility.js b/src/libs/accessibility.js new file mode 100644 index 0000000..095e953 --- /dev/null +++ b/src/libs/accessibility.js @@ -0,0 +1,12 @@ +import lodash from 'lodash' + + +// Throttle for 3 seconds so when a user enables it they don't have to refresh the page. +const reducedMotionEnabled = lodash.throttle(() => { + return window.matchMedia("(prefers-reduced-motion: reduce)").matches +}, 3000); + + +export default { + reducedMotionEnabled +}