fix: pass the animation event to onAnimationEnd - #575
Merged
Merged
Conversation
The handler dropped the animation event and also reacted to animationend events bubbling up from elements inside the modal. A child animation could trigger onAnimationEnd and, while closing, unmount the portal before the modal exit animation finished. Pass the React.AnimationEvent to onAnimationEnd and ignore events whose target is not the modal element itself. Closes #522
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #575 +/- ##
==========================================
+ Coverage 80.40% 80.69% +0.29%
==========================================
Files 7 7
Lines 199 202 +3
Branches 73 74 +1
==========================================
+ Hits 160 163 +3
Misses 29 29
Partials 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #522.
Problem
onAnimationEndwas declared and called without arguments, so consumers could not inspect what caused the event.While investigating I found the handler is attached to the modal dialog and React's
animationendbubbles, so any animation ending inside the modal triggered the callback. Worse, while closing, a child animation ending would runsetShowPortal(false)and unmount the modal before its own exit animation finished.Fix
React.AnimationEvent<HTMLDivElement>toonAnimationEnd.targetis not the modal element itself, so child animations no longer trigger the callback or unmount the modal early.() => voidhandlers remain assignable, so this is not a breaking change.Tests
Added regression tests covering:
onAnimationEndonAnimationEnd