From 37c85ec7e2533a002f3147e17a67e4ce7d760a5e Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 9 Feb 2019 19:52:40 -0800 Subject: [PATCH] fix: disable smooth scroll for users who prefer reduced motion (#958) --- src/routes/_utils/smoothScroll.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/routes/_utils/smoothScroll.js b/src/routes/_utils/smoothScroll.js index 4a520f2..bc1325f 100644 --- a/src/routes/_utils/smoothScroll.js +++ b/src/routes/_utils/smoothScroll.js @@ -1,3 +1,5 @@ +import { store } from '../_store/store' + // via https://github.com/tootsuite/mastodon/blob/f59ed3a4fafab776b4eeb92f805dfe1fecc17ee3/app/javascript/mastodon/scroll.js const easingOutQuint = (x, t, b, c, d) => c * ((t = t / d - 1) * t * t * t * t + 1) + b @@ -62,7 +64,10 @@ function testSupportsSmoothScroll () { export const hasNativeSmoothScroll = process.browser && testSupportsSmoothScroll() export function smoothScroll (node, topOrLeft, horizontal) { - if (hasNativeSmoothScroll) { + if (store.get().reduceMotion) { + // don't do smooth-scroll at all for users who prefer reduced motion + node[horizontal ? 'scrollLeft' : 'scrollTop'] = topOrLeft + } else if (hasNativeSmoothScroll) { return node.scrollTo({ [horizontal ? 'left' : 'top']: topOrLeft, behavior: 'smooth'