polaris icon indicating copy to clipboard operation
polaris copied to clipboard

[a11y] Look into reduced motion media query to leverage reduced motion preferences

Open lemonmade opened this issue 9 years ago • 9 comments

lemonmade avatar Apr 07 '17 21:04 lemonmade

Any traction on this? Not too hard to pull off. In Scrollable you do: https://github.com/Shopify/polaris-react/blob/master/src/components/Scrollable/Scrollable.tsx#L254-L260

You can extract that into a utility that you can then import:

function prefersReducedMotion() {
  try {
    return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  } catch (err) {
    return false;
  }
}

export const PREFERS_REDUCED_MOTION = prefersReducedMotion();

After that, you can do something like:

export enum TransitionType {
  slideIn = 'slideIn',
  slideUp = 'slideUp',
  fade = 'fade',
}

// TODO: Import value from polaris-tokens
// https://github.com/Shopify/polaris-tokens/pull/54
const DEFAULT_TRANSITION_DURATON = 300;
const REDUCED_MOTION_TYPES = [TransitionType.slideIn, TransitionType.slideUp];

const duration = PREFERS_REDUCED_MOTION && REDUCED_MOTION_TYPES.includes(TransitionType.fade) ? 0 : DEFAULT_TRANSITION_DURATON;

And in SCSS you can just create a mixin:

// Set animation + transition duration to `1ms` for prefers-reduced-motion users
// @param {Boolean} $disable (optional) - Completely disable transitions,
// or set to `false` and provide your own alternate transition rules.
@mixin reduce-motion($disable: true) {
  @media screen and (prefers-reduced-motion: reduce) {
    @if ($disable) {
      // stylelint-disable-next-line declaration-no-important
      animation-duration: 1ms !important;
      // stylelint-disable-next-line declaration-no-important
      transition-duration: 1ms !important;
    }

    @content;
  }
}

Setting to duration: 1ms !important; should still allow event listeners to function correctly.

Generally, I will @include reduce-motion; at the bottom of a style declaration when using any transform/width/height/position type of motion. Otherwise, opacity and color changes seem to be acceptable to leave alone.

cc/ @dpersing in case you have any input

beefchimi avatar Mar 18 '19 19:03 beefchimi

Support has now been added to Chrome! https://twitter.com/ChromiumDev/status/1121132751200104448

dpersing avatar Apr 24 '19 20:04 dpersing

@yourpalsonja I'd love if we could get this implemented sooner than later.

dpersing avatar May 07 '19 14:05 dpersing

@dpersing Shouldn't require too much time, most of what I commented on above is directly transferable. Testing is a bit tricky, as I have yet to figure out how to do this in my own projects. As far as I know, the prefers-reduced-motion does not work in our test environment.

The above can ship as its own PR. Then separate follow up PRs can implement it in each component that uses motion.

I'd try to implement this myself, but am going to be too busy with Online Store Web 😞

beefchimi avatar May 07 '19 15:05 beefchimi

This issue still requires explorations and a deep dive into the problem.

mirualves avatar Nov 06 '19 15:11 mirualves

Requirements:

  • [ ] Designers consider animation alternatives in the design process
  • [ ] FEDs implement reduced motion without exception
  • [ ] Reduced motion settings have intended effect

Prompts:

  • What's the MVP of that?
  • What are the main benefits of having a centralized approach? What are the things that need to scale? What are the levers we might wanna pull centrally – and why?
  • What are some scalable, automated, or facilitating ways we could meet the requirements above?

Is the real problem that we're lacking a unified approach to animation? The approach to reduced motion need to work well with our approach to transitions and animations. Are there any constraints or opportunities in that relationship? Do we even have a unified approach to implementing transitions? Perhaps that's the real issue, and that reduced motion needs to be an integral part of that?


See "beta docs" in the Vault Animation and Accessibility (internal only for now, sorry about the inconvenience)

johanstromqvist avatar Jun 03 '22 10:06 johanstromqvist

FEDs implement reduced motion without exception […] The approach to reduced motion need to work well with our approach to transitions and animations. Are there any constraints or opportunities in that relationship? Do we even have a unified approach to implementing transitions? Perhaps that's the real issue, and that reduced motion needs to be an integral part of that?

I’m not super familiar with transitions/animations in Polaris and how they’re currently authored, but I thought I’d still chime in with my FED perspective and past experience on reduced motion 👀

At my previous job, we were setting the value of a global --duration CSS variable to either 1 or 0 depending on the value of the prefers-reduced-motion media query. Using a Fela CSS-in-JS plugin, we automatically processed any animation or transition duration (and delay!) from e.g. 250ms to be calc(var(--duration) * 250ms) instead. So when a user prefers reduced motion, all of the duration values would be set to 0, thus skipping any transition or animation. My ex-colleague Kitty wrote a blog post about the implementation, if you’re curious.

We could probably achieve something similar in this repository with postCSS or a linter rule. Then FEDs wouldn’t really ever have to think about it when they author animations/transitions.

Worth noting we were ignoring all transitions and animations though, which might not necessarily be what a user wants; it’s called “reduced motion” and not “no motion” after all. With this implementation you could let the user themselves decide on a specific duration “modifier” though. 🤔

Some animations are purely “decorative” whereas some are more “meaningful”; maybe we need a way to be able to mark them as such? e.g. “decorative” animations would be entirely skipped whereas the “meaningful” ones would be sped up?

Tom-Bonnike avatar Jun 03 '22 11:06 Tom-Bonnike

Thanks @Tom-Bonnike!

Worth noting we were ignoring all transitions and animations though, which might not necessarily be what a user wants; it’s called “reduced motion” and not “no motion” after all.

^ I very much agree with this. Perhaps we can use a "duration = 0" method as a fallback?

  • Ideally designers and devs collaborate on creating and implementing the ideal experience for all preferences
  • A fallback that respects any intentional implementations, but reduces duration to 0 where we failed to implement one

[...] Then FEDs wouldn’t really ever have to think about it when they author animations/transitions.

^ Would we want devs to not be concerned with a11y? Perhaps the ideal would be:

  • Some devs could forget about reduced motion, and we'd still catch it and mitigate damage on the product
  • Most devs do practice it, so that awareness, best practices and quality continuously improve. Aware devs can push designers to focus on the issues and create better alternatives.

johanstromqvist avatar Jun 03 '22 12:06 johanstromqvist

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's design system and dev experience.

github-actions[bot] avatar Apr 07 '23 03:04 github-actions[bot]