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

[popups] Add onCloseComplete callback #1235

Merged
merged 6 commits into from
Jan 8, 2025
Merged

Conversation

atomiks
Copy link
Contributor

@atomiks atomiks commented Dec 26, 2024

Closes #1208

@atomiks atomiks added component: select This is the name of the generic UI component, not the React module! component: menu This is the name of the generic UI component, not the React module! component: alert dialog This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module! component: dialog This is the name of the generic UI component, not the React module! component: popover The React component. component: preview card The React component. labels Dec 26, 2024
@mui-bot
Copy link

mui-bot commented Dec 26, 2024

Netlify deploy preview

https://deploy-preview-1235--base-ui.netlify.app/

Generated by 🚫 dangerJS against 8460035

@atomiks atomiks marked this pull request as ready for review December 26, 2024 11:37
@atomiks
Copy link
Contributor Author

atomiks commented Dec 27, 2024

Naming:

  • onHidden may be confusing since it doesn't relate to the open/closed concepts in the API. You can also hide the popup with data-anchor-hidden even though it's still open.
  • onClosed may be confusing since [data-closed] is applied as soon as open: false. Maybe onCloseComplete/onClosedComplete?
  • onOpenChangeComplete (as mentioned in the issue) is needlessly symmetric since you only need to care about open: false completing, not open: true (presumably? You can at least replicate it externally semi-easily)

@michaldudak
Copy link
Member

onCloseComplete looks less confusing that onClosed IMO.

Comment on lines 132 to 135
let onClosedCalled = false;
function notifyOnClosed() {
onClosedCalled = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let onClosedCalled = false;
function notifyOnClosed() {
onClosedCalled = true;
}
const notifyOnClosed = spy();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sinon's spy can be used instead (it can also verify if the function was called exactly once)

Copy link
Contributor Author

@atomiks atomiks Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technique was already used for the existing animation tests, it'd probably be worth updating them all simultaneously in a separate PR

@atomiks atomiks changed the title [popups] Add onClosed callback [popups] Add onCloseComplete callback Jan 7, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 8, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 8, 2025
@atomiks atomiks merged commit 412b1bd into mui:master Jan 8, 2025
23 checks passed
@atomiks atomiks deleted the feat/onClosed branch January 8, 2025 07:29
@vladmoroz
Copy link
Contributor

A bit late to barge in

  • onOpenChangeComplete (as mentioned in the issue) is needlessly symmetric since you only need to care about open: false completing, not open: true (presumably? You can at least replicate it externally semi-easily)
  • You may want to start an in-content video or animation when the popup or panel open animation is complete
  • Being closer to onOpenChange makes for a simpler, easier to remember API

@atomiks
Copy link
Contributor Author

atomiks commented Jan 8, 2025

@vladmoroz I can see those points being valid, but reacting to close completing (when unmounting) requires this prop to exist, since you can't use onTransitionEnd/onAnimationEnd as they fail to get called in time. This doesn't happen for open: true. Is it too difficult to use those events externally? We'd have to use those props at the very least internally, adding extra bundle cost for a possibly rare use case

@vladmoroz
Copy link
Contributor

I just think it's an odd API when one case is provided via a prop and a symmetrical one is fully DIY. Seems arbitrarily inflexible.

I agree that it's a less common use case

@atomiks
Copy link
Contributor Author

atomiks commented Jan 8, 2025

Alright, let me try to make a new PR that reuses the existing node.getAnimations() util, but supports the open use case as well and rename to onOpenChangeComplete

@atomiks atomiks restored the feat/onClosed branch January 8, 2025 11:29
@atomiks atomiks deleted the feat/onClosed branch January 8, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: alert dialog This is the name of the generic UI component, not the React module! component: dialog This is the name of the generic UI component, not the React module! component: menu This is the name of the generic UI component, not the React module! component: popover The React component. component: preview card The React component. component: select This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dialog, Popover] Provide a callback for open/close completion
4 participants