Skip to content

Commit

Permalink
Fix end listener
Browse files Browse the repository at this point in the history
  • Loading branch information
otomad committed Apr 16, 2024
1 parent 4ab4e48 commit a426f80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/Transition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,11 @@ const Transition = functionModule(
{...props}
{...(props.timeout != null ?
{ timeout: props.timeout }
: { nodeRef, addEndListener: endListener() })}
: {
nodeRef,
addEndListener:
props.addEndListener ?? endListener(),
})}
>
{cloneRef(props.children as ReactNode, nodeRef)}
</TransitionComponent>
Expand Down
14 changes: 6 additions & 8 deletions src/utils/cloneRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ export function endListener() {
* @param done A callback function to be executed when the animation ends.
*/
return (node: HTMLElement, done: () => void) => {
node?.addEventListener(
"transitionend",
(e) => {
if (e.target !== e.currentTarget) return;
done();
},
false,
);
const listener = (e: TransitionEvent) => {
if (e.target !== e.currentTarget) return;
node?.removeEventListener("transitionend", listener, false);
done();
};
node?.addEventListener("transitionend", listener, false);
};
}

0 comments on commit a426f80

Please sign in to comment.