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

[Presence] Ensure onAnimationEnd when closing #1849

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

YarnSphere
Copy link
Contributor

@YarnSphere YarnSphere commented Dec 19, 2022

Make sure that onAnimationEnd is fired for consumers, after the closing animation of a component.

Fixes: #1020

I hit #1020 when implementing an imperative API over toasts, where I want to remove a toast from the list of open toasts after it finishes its "close" animation. I expect wanting to know when an element finishes closing to be a relatively common need.

@YarnSphere
Copy link
Contributor Author

YarnSphere commented Dec 19, 2022

A completely different approach to solving #1020 would be to change the Presence component to receive an extra property onAnimationEnd (the same event handler that would otherwise have been passed to the component we are animating) and manually call onAnimationEnd before we call flushSync.

This would require going through every usage of Presence in Radix and pass it the onAnimationEnd handler that was being passed to the animating component.

The biggest downside of this approach (besides the fact that we're complicating Presence) is that we'd have mismatched signatures for onAnimationEnd, since we're dealing with "real" events here, rather than synthetic ones, so we'd likely have to deal with that discrepancy somehow.

What are your thoughts? Do you have any other ideas on how to solve this? I'm leaving this PR here with this possible solution, but am happy to change the approach if you find it inadequate.

Make sure that `onAnimationEnd` is fired for consumers, after the
closing animation of a component.

Fixes: radix-ui#1020
@chaance chaance merged commit 8d9bc46 into radix-ui:main Sep 26, 2024
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

Successfully merging this pull request may close these issues.

[Presence] onAnimationEnd doesn't fire on close
2 participants