Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transitionEnd() doesn't work as expected if event fires on child node but not node itself #184

Open
zorac opened this issue May 10, 2024 · 0 comments

Comments

@zorac
Copy link

zorac commented May 10, 2024

I was seeing an issue with react-bootstrap <Modal>s sometimes not being removed after completing their exit transition (and thus remaining on-screen and blocking any further user interaction.) This appears to be due to the transitionend event not firing on the top level DOM node, but other transitionend events firing on child nodes and bubbling up.

dom-hepers' transitionEnd has a check to emulate the transitionend event if on hasn't been seen after a timeout, however a event bubbling up from a child node will also count as the event being "seen" and thus no event is emulated. A quick patch which would change that behaviour:

diff --git a/src/transitionEnd.ts b/src/transitionEnd.ts
index cef860e..d26d7d0 100644
--- a/src/transitionEnd.ts
+++ b/src/transitionEnd.ts
@@ -25,10 +25,9 @@ function emulateTransitionEnd(
   const remove = listen(
     element,
     'transitionend',
-    () => {
-      called = true
-    },
-    { once: true }
+    (event) => {
+      if (event.target === element) called = true
+    }
   )
 
   return () => {

Side-note: a userland workaround for my specific issue is to wrap the <ModalDialog> component and stop the propagation of any transitionend events there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant