-
Notifications
You must be signed in to change notification settings - Fork 45
fix(Popover): unnecesary call of onOpen and missing call of onClose
#4230
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
Conversation
🦋 Changeset detectedLatest commit: 4ab3095 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Preview deployments for this pull request: storybook - |
7fd7b2d to
cd112c2
Compare
…hen closed via Trigger also when controlled
cd112c2 to
dfdee89
Compare
| event.preventDefault(); // Prevent native Popover API | ||
| setInternalOpen((open) => !open); | ||
| onOpen?.(); | ||
| if (!controlledOpen) { |
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.
Nitpick, but to make it more readable, could we swap the ifs, so we can do if (controlledOpen)?
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.
Were you thinking something like this? Not sure if it's actually more readable, but at least we only have the close logic once in this version.
if (controlledOpen) {
if (isTrigger) {
event.preventDefault(); // Prevent native Popover API
}
if (isTrigger || isOutside) {
setInternalOpen(false);
onClose?.();
}
} else if (isTrigger) {
event.preventDefault(); // Prevent native Popover API
setInternalOpen(true);
onOpen?.();
}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.
Or maybe like this
if (isTrigger) {
event.preventDefault(); // Prevent native Popover API
}
if (controlledOpen && (isTrigger || isOutside)) {
setInternalOpen(false);
onClose?.();
} else if (isTrigger) {
setInternalOpen(true);
onOpen?.();
}
};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.
Liked your last suggestion, went ahead and added it to the PR
|
I'll make sure to fix this before next release 😄 |
Summary
Popover: Fix unnecesary call of
onOpenand missing call ofonCloseonOpenwhen clickingPopover.TriggerwhenPopoveris already open.onClosewhen a controlledPopoveris closed by clicking onPopover.Trigger.Checks
pnpm changesetif relevant)