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

Modal inside modal: closing the first modal closes the second #68

Open
vicjune opened this issue Feb 9, 2022 · 1 comment
Open

Modal inside modal: closing the first modal closes the second #68

vicjune opened this issue Feb 9, 2022 · 1 comment

Comments

@vicjune
Copy link

vicjune commented Feb 9, 2022

const FirstModal = ({ closeFirstModal }) => {
  const [openSecondModal] = useModal(() => <div>Second modal</div>);

  return (
    <div
      onClick={() => {
        openSecondModal();

        // This closes the second modal as well but it should not
        closeFirstModal();
      }}
    >
      First modal
    </div>
  );
};

const Page = () => {
  const [openFirstModal, closeFirstModal] = useModal(() => (
    <FirstModal closeFirstModal={closeFirstModal} />
  ));

  return <div onClick={openFirstModal}>Click me</div>;
};

In this situation, you click on the div Click me -> it displays First modal

Then when you click on the div First modal:

Expected behaviour: It should display Second modal and close FirstModal

What happens: It closes FirstModal and displays Second modal for a fraction of a second before closing it

@vicjune vicjune changed the title Modal inside modal: closing the first modal close the second Modal inside modal: closing the first modal closes the second Feb 9, 2022
@zbyte64
Copy link

zbyte64 commented Aug 30, 2022

Was looking for a "fire and leave" pattern, I have a menu item triggering a modal. This runs into the same problem here, the hook will cleanup, ie close the modal, when the parent component unmounts: https://github.com/mpontus/react-modal-hook/blob/master/src/useModal.ts#L64

Perhaps an optional flag could be added to disable the clean up?

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