-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
[popups] onOpenChangeComplete
prop
#1305
Conversation
Netlify deploy preview |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
05afb45
to
aec975d
Compare
onOpenChangeComplete
prop
Signed-off-by: atomiks <cc.glows@gmail.com>
* Calls the provided function when the CSS open animation or transition completes. | ||
*/ | ||
export function useOpenChangeComplete(parameters: useOpenChangeComplete.Parameters) { | ||
const { open, change = 'close', ref, onComplete: onCompleteParam } = parameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a bit more readable if this change
param didn't have a default, but it probably doesn't matter outside of looking at this code in Github
anyway I tested onOpenChangeComplete
in a bunch of our hero demos and it works well (they all use CSS transitions) 👍
CC @michaldudak to review the implementation as well 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was a small optimization since it's called in many of the root components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Albert, not having this parameter present when calling the hook makes it more confusing: we're calling useOpenChangeComplete
, but its onComplete
handles just the closing part.
TBH the change
prop itself isn't super clear and I had to spend some time to understand what it's for. Would it be possible to remove it and make the hook handle both cases at the same time? The second parameter to runOnceAnimationsFinish
could perhaps be derived from open
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it so the caller with onComplete
specified needs to check the change direction
useTooltipRootContext(); | ||
const { side, align } = useTooltipPositionerContext(); | ||
|
||
useOpenChangeComplete({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this can't be handled in useTooltipRoot, as the close animation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timing of the ref assignment means it needs to be called in the popup component to be accessible
* Calls the provided function when the CSS open animation or transition completes. | ||
*/ | ||
export function useOpenChangeComplete(parameters: useOpenChangeComplete.Parameters) { | ||
const { open, change = 'close', ref, onComplete: onCompleteParam } = parameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Albert, not having this parameter present when calling the hook makes it more confusing: we're calling useOpenChangeComplete
, but its onComplete
handles just the closing part.
TBH the change
prop itself isn't super clear and I had to spend some time to understand what it's for. Would it be possible to remove it and make the hook handle both cases at the same time? The second parameter to runOnceAnimationsFinish
could perhaps be derived from open
?
Co-authored-by: Michał Dudak <michal.dudak@gmail.com> Signed-off-by: atomiks <cc.glows@gmail.com>
Signed-off-by: atomiks <cc.glows@gmail.com>
@@ -63,9 +63,10 @@ const AlertDialogPopup = React.forwardRef(function AlertDialogPopup( | |||
useOpenChangeComplete({ | |||
open, | |||
ref: popupRef, | |||
change: 'open', | |||
onComplete() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most straightforward and idiomatic way to use this would be to have a parameter on the onComplete
callback that determines if the popup was opened or closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of that, but it's not actually necessary because you can just use the outer variable that's passed as open
. The useEventCallback
ensures it's not stale.
Closes #1208
New alternative to #1235 to support both symmetric open/close cases, which has a more intuitive API.
useAfterExitAnimation
to support both open/close animationsonOpenChangeComplete
is called withopen: boolean