Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a disable option to disable/reduce animation #124

Closed
walopee opened this issue Apr 14, 2022 · 9 comments
Closed

Provide a disable option to disable/reduce animation #124

walopee opened this issue Apr 14, 2022 · 9 comments

Comments

@walopee
Copy link

walopee commented Apr 14, 2022

Expected behavior
It would be nice to have the option to conditionally disable the animation for users who have their OS settings set to reduced or no animations

Your Environment

  • Version used: 2.0.23
  • OS: Windows 10 (turn off "Show animation in Windows" setting)
  • Browser: Chrome

Additional context
This would help fulfill an accessibility best practice by allowing users the option to avoid animations (https://www.w3.org/TR/WCAG21/#animation-from-interactions). I did just realize that this is also achievable by setting the duration to 0 when needed, though 😅

@Stanko
Copy link
Owner

Stanko commented Apr 14, 2022

Hey @walopee, that is a good point. I'll take a look this weekend.

For now you can add a simple workaround, by checking for (prefers-reduced-motion) using matchMedia:

Live demo:
https://codesandbox.io/s/sleepy-panna-2ohhf1?file=/src/App.js

Code:

import { useState } from "react";
import AnimateHeight from "react-animate-height";

export default function App() {
  const [height, setHeight] = useState("auto");
  const reducedMotion = matchMedia("(prefers-reduced-motion)").matches;

  return (
    <div>
      <button onClick={() => setHeight(height === 0 ? "auto" : 0)}>
        Toggle
      </button>
      <AnimateHeight height={height} duration={reducedMotion ? 0 : 500}>
        <div
          style={{
            padding: "50px 20px",
            background: "#eee",
            border: "1px solid #ddd",
            marginTop: 20
          }}
        >
          Hello World
        </div>
      </AnimateHeight>
    </div>
  );
}

@Stanko
Copy link
Owner

Stanko commented Apr 15, 2022

Component now respects prefers-reduced-motion flag, published in 2.1.1:

b7fd78d#diff-af8ea84e12681096191e9bd85c5d016e492d25a9fd8baeedb117a0b6ee46f593

Cheers!

@Stanko Stanko closed this as completed Apr 15, 2022
@Bdragon93
Copy link

@Stanko is there any way to enable it? I'd like to force the application to keep the animation for all users even if they set reduce motion, would be great if there's an option as a prop to turn it on/off

@Stanko
Copy link
Owner

Stanko commented Apr 18, 2023

Hey @Bdragon93,
You can just pass duration={0} and the animation will be disabled.
If you want to control it, you can use a boolean parameter duration={ isDisabled ? 0 : 500 }

Cheers!

@Bdragon93
Copy link

@Stanko unfortunately it doesn't work for me. even from your live demos and codesandbox example

Version used: 3.1.1
OS: MacOS 13.2.1, turning on "reduce motion"
Browser: Chrome
Browser Version: 112.0.5615.121

@Stanko
Copy link
Owner

Stanko commented Apr 18, 2023

@Bdragon93
Copy link

@Stanko I just tried on another Macbook and more browsers - safari/firefox, not work for all.

@Bdragon93
Copy link

additionally, my devices use chip Apple M1, in case it's related

@Stanko
Copy link
Owner

Stanko commented Apr 18, 2023

If a user has "reduce motion" flag on, animation won't work, as that would breaks accessibility. I won't implement "force animation" prop.

It works as intended on Chrome, Firefox and Safari.

Here is video of Firefox and Chrome with the same sandbox I sent you earlier:
https://codesandbox.io/s/react-animate-height-v3-disable-animation-8ncjjv?file=%2Fsrc%2Findex.js

disabled-animation.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants