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

How to close a modal when navigating away #2

Open
mrhighstone opened this issue Dec 11, 2024 · 2 comments
Open

How to close a modal when navigating away #2

mrhighstone opened this issue Dec 11, 2024 · 2 comments

Comments

@mrhighstone
Copy link

I'm using this awesome plugin, and on one of the modals a link is being shown. When the link is clicked and the user navigates to another page (within the application) the modal dialog remains open. The page underneath refreshes. How can the modal be closed/dismissed/rejected when the user navigates away from the current page?

I'm successfully using this with headlessui plugin in a Vue application, but I haven't found a decent solution to this. Any ideas?

@AndrewBastin
Copy link
Owner

AndrewBastin commented Dec 11, 2024

@mrhighstone ahhhh, that is an interesting problem that I have missed in the design of the library. Good catch :)

So, here is my proposal I would love to get your feedback on, what if we automatically reject modals when the component which called openModal on it gets unmounted ?

On the technical implementation side, when you call useModals composable to get access to the openModal function, that specific instance of openModal will reject any unresolved modal when that component (which called useModal to get that function) unmounts.

Does this work for you ? Any corner case or better heuristic you think I might have missed ?

@mrhighstone
Copy link
Author

I think that would be a perfect, and logical solution to do so.
I cannot think of any edge cases at the moment.

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