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
758 stars 53 forks source link

onAnimationEnd and children #61

Closed pryahin closed 6 years ago

pryahin commented 6 years ago

Hello, I found a strange behavior on the onAnimationEnd event. If an element has a child that has an animation, the onAnimationEnd event will be triggered after the animation of the child has completed.

I think that onAnimationEnd should only work for AnimateHeight element, and should not be triggered on children's animations.

Stanko commented 6 years ago

Hello @pryahin, I can't replicate what you are describing, check the quick example I made: https://codesandbox.io/s/241mpxk9x0

Please try to recreate the issue on https://codesandbox.io so I can investigate what is happening.

Cheers!

pryahin commented 6 years ago

I meant that if an element has a css-animation and at the same time it is an AnimateHeight child, then at the end of the animation of this element, the parent's onAnimationHeight will work

Try adding this code to the style.css

@keyframes open {
  from {
    opacity: 0;
  }
  to {
    opacity: 1
  }
}

h2 {
  animation: open 1s ease-in-out
}
Stanko commented 6 years ago

Woah! 😄 Great catch, I think I know what it is. Let me investigate and I'll get back to you asap.

Stanko commented 6 years ago

@pryahin bug fixed in version 2.0.5 🎉

I just omitted onAnimationStart and onAnimationEnd from being passed to the element directly. https://github.com/Stanko/react-animate-height/blob/b491426085705f7f6766c41995561e0ed08ecbad/source/AnimateHeight.js#L18-L30

Thing is that callback names were identical to the native DOM handlers, and they were attached here:

https://github.com/Stanko/react-animate-height/blob/b491426085705f7f6766c41995561e0ed08ecbad/source/AnimateHeight.js#L333-L335

I'm passing all props to the element to allow users to pass any accessibility props directly to the div, but I forgot to omit these two.

Links to the native event handlers:

I updated the example here: https://codesandbox.io/s/r47yk1ml84

Cheers!