From 858c6e8a1ca4065690a5087ec14bea204653c4e7 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Thu, 31 Oct 2024 19:19:57 +0100 Subject: [PATCH] Let CSSTransition use the transitionend event if there is no duration. --- src/CSSTransition.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/CSSTransition.ts b/src/CSSTransition.ts index 0f6e290..f08ce48 100644 --- a/src/CSSTransition.ts +++ b/src/CSSTransition.ts @@ -51,6 +51,19 @@ const computeClassName = (phase: Phase, classNames: CSSTransitionClassNames) => export default (props: CSSTransitionProps): VNode => { const { children, classNames, ...rest } = props; + + if (!rest.duration) { + const addEndListener = rest.addEndListener; + + rest.addEndListener = (node: Element, done: () => void) => { + if (addEndListener) { + addEndListener(node, done); + } else { + node.addEventListener("transitionend", done, { once: true }); + } + }; + } + return createElement(Transition, rest, (state, phase: Phase) => { const { className } = children.props;