Stanko / react-animate-height

Lightweight React component for animating height using CSS transitions. Slide up/down the element, and animate it to any specific height.
https://muffinman.io/react-animate-height
MIT License
756 stars 53 forks source link

Element no longer animates up and down when using "auto" #149

Closed WhereCanI closed 4 months ago

WhereCanI commented 12 months ago

react-animate-height no longer animate up and down when used with React. It is the same problem with the demos provided here: https://muffinman.io/react-animate-height/#demo-3. They no longer animate up and down pending on the content.

Expected behavior Animating from height 0 to height "auto".

Your Environment

Additional context I have checked that the container is following the guidelines, and I have even tried removing all styling such as padding, margin, display, flex from parent containers. Nothing seem to work to make react-animate-height animate from 0 to "auto".

Stanko commented 12 months ago

Hey, I’m not near my laptop, but if I understood correctly, you want to animate height on content change.

That is not supported out of the box, but it can be achieved by using ResizeObserver.

Check the documentation for the code example: https://github.com/Stanko/react-animate-height#animate-height-on-content-change

Cheers!

WhereCanI commented 11 months ago

No, it's not what I mean. What I mean is that I no longer can make it animate from 0 to auto. It used to be able to do that, but now it won't do it no matter how I add it to my React projects.

I have tried to troubleshoot by making sure there are no CSS that can break the calculation. But it does not make a difference.

I have a suspicion that it might break the animation if the change between 0 and auto is triggering React to rerender.

Stanko commented 11 months ago

Please create provide a sandbox (https://codesandbox.io/), because I have no idea what the problem actually is.

eseQ commented 7 months ago

I faced same issue but there was because i used '0%' instead of 0 as number

IsabellaRey commented 5 months ago

Hi, is this being looked into? I think I'm facing the same problem as described. I'm upgrading from v2.0.7 to v3.2.3 and the animation when opening/closing is no longer there

For example:

<AnimateHeight height={props.isExpanded ? 'auto' : 0} duration={3000} delay={2000}>
    <MyStuff....>
</AnimateHeight>

just flicks between open and close, with no smooth animation

Stanko commented 5 months ago

Hey, I'm not working on it as I can't reproduce it.

Can you please try to fork this codepen to recreate the issue you are having https://codepen.io/stanko/pen/NWmaGjX

Once I know what is wrong I'll look into fixing it.

Cheers!

edwiles commented 5 months ago

I'm a colleague of @IsabellaRey - turns out that we're using a virtual desktop in which the Windows setting "Animation effects" was disabled by default. Your codepen above works if Animation effects is on, but not if it is off (unlike 2.0.7 which works either way). I presume this is due to a change in how the animation is produced?

Stanko commented 5 months ago

Hi @edwiles, That is correct, the library respects user's preferences to reduce motion. The actual code is here:

https://github.com/Stanko/react-animate-height?tab=readme-ov-file#reduced-motion

I won't be providing a way around it, as it would break accessibility.

Hope that makes sense, cheers!

Stanko commented 5 months ago

Hey @WhereCanI Could it be that you also had "reduce motion" option enabled?

Stanko commented 4 months ago

I'm closing this issue for now, if you can create a way to replicate it, I'll dig deeper. Thank you!