Closed remijean closed 4 years ago
Hey @remijean, I think the problem here are native animation callbacks (onanimationstart for example).
HTMLAttributes<HTMLDivElement>
have to be there, so users can easily add other attributes (aria-*
for example).
I think changing the order should fix it
export type AnimateHeightProps = HTMLAttributes<HTMLDivElement> & {
/* props go here */
};
I'll publish a new version soon.
Published in 2.0.18, can you please try it?
@Stanko always the same error :cry:
Oh, I think I know what it is. It seems it is clashing with native attributes: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onanimationstart https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onanimationend
I'll try to fix it this weekend.
I could rename callback props, but I would like to avoid it as it makes a breaking change.
I just tested it with version 2.0.18 and react create app (with typescript), and everything works as expected. This is the exact code I'm using:
import React, { useState } from 'react';
import AnimateHeight from 'react-animate-height';
const Home: React.FC = () => {
const [height, setHeight] = useState<string|number>(0);
return (
<div>
<button onClick={() => setHeight(height === 0 ? 'auto' : 0)}>Toggle</button>
<AnimateHeight
height={height}
onAnimationStart={() => console.log('start')}
onAnimationEnd={() => console.log('end')}
>
Vestibulum eget purus in risus elementum bibendum.
Nunc et sapien mattis, tincidunt mi ut, sollicitudin mi. Morbi vel nunc enim.
Nunc vehicula ligula magna, non mattis neque suscipit in.
</AnimateHeight>
</div>
);
}
export default Home;
Please make sure you updated to 2.0.18
@Stanko Yes that's right, you can try to use Omit /Pick / Exclude to overwrite the two attributes: https://stackoverflow.com/a/56916686 https://stackoverflow.com/a/48216010
@Stanko I'll check again :+1:
Thank you! I think the order change I did:
export type AnimateHeightProps = HTMLAttributes<HTMLDivElement> & AnimateHeightProps;
should do the trick. As far as I understand it AnimateHeightProps' onAnimationStart/End
should overwrite the HTMLAttributes ones.
@Stanko results of my new test:
This code works:
import React, { FC } from 'react'
import AnimateHeight from 'react-animate-height'
export const Test: FC = () => {
return (
<AnimateHeight onAnimationStart={() => console.log(true)}>
Hello world!
</AnimateHeight>
)
}
export default Test
This code doesn't work:
import React, { FC } from 'react'
import AnimateHeight from 'react-animate-height'
export const Test: FC = () => {
return (
<AnimateHeight onAnimationStart={(props: { newHeight: number }) => console.log(props.newHeight)}>
Hello world!
</AnimateHeight>
)
}
export default Test
Screenshot:
My packages.json:
Dang! My bad again 🙈 Omit
it is! I'll try to get the new version out asap.
There it goes, please try version 2.0.19
And thank you for bearing with me :)
It is not my day today, I added onAnimationStart
twice :/ and forgot onAnimationEnd
2.0.20 coming up
Published 2.0.20 🎉 I made this way more complicated than it should be :)
Ahah, thank you it works perfectly! :fire:
Code example
Expected behavior Typescript error
Type '(props: { newHeight: number; }) => void' is not assignable to type '(event: AnimationEvent<HTMLDivElement>) => void
:Possible Solution
Remove
& HTMLAttributes<HTMLDivElement>
?