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

[Request] Add default to remove modal #131

Open
dml0031 opened this issue Oct 11, 2023 · 3 comments
Open

[Request] Add default to remove modal #131

dml0031 opened this issue Oct 11, 2023 · 3 comments

Comments

@dml0031
Copy link

dml0031 commented Oct 11, 2023

I have been using this package for a long time in a lot of projects and recently ive noticed a lot of issues regarding modals mounting and un-mounting especially with forms.

Most UI packages have modals built with open / closing animations and id like to use that closing animation, so if I just call modal.remove() the animation is not displayed. Ive tried to do an async call like this:

const handleClose = async () => {
  return modal.hide().then(() => modal.remove())
}

however in that scenario I have noticed that the modals are not actually being removed from the component tree and if I were to open that modal again, the form values still display the values of the previous modal because it did not get removed and re-rendered.

@supnate
Copy link
Collaborator

supnate commented Oct 12, 2023

Which UI library do you use? You need to call modal.remove() from the callback like afterHideAnimation of the Modal component from the UI lib. For example, the built-in muiDialogV5 helper calls modal.remove when onExited:

export const muiDialogV5 = (
  modal: NiceModalHandler,
): { open: boolean; onClose: () => void; TransitionProps: { onExited: () => void } } => {
  return {
    open: modal.visible,
    onClose: () => modal.hide(),
    TransitionProps: {
      onExited: () => {
        modal.resolveHide();
        !modal.keepMounted && modal.remove();
      },
    },
  };
};

See the code here:

onExited: () => {

@dml0031
Copy link
Author

dml0031 commented Oct 12, 2023

This is the library NextUI

I tried to use onAnimationEnd for the modal.remove() call but it was still not removing it from the component tree afterwards.

@supnate
Copy link
Collaborator

supnate commented Oct 13, 2023

@dml0031 can you create a codesandbox sample?

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

No branches or pull requests

2 participants