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 closes when selecting a field. #505

Open
sahil839 opened this issue Nov 12, 2022 · 5 comments
Open

Modal closes when selecting a field. #505

sahil839 opened this issue Nov 12, 2022 · 5 comments

Comments

@sahil839
Copy link

sahil839 commented Nov 12, 2022

Current behavior - Selecting a field or text in the modal closes it if mouse is dragged outside the modal.

Example from zulip project-
selecting-inside-modal

Can be reproduced while selecting some text in the demo modal in documentation as well.
demo-micromodal

Expected behavior - Modal should not closed if mouse ends up outside the modal while selecting something.

@sahil839
Copy link
Author

One possible solution could be to add the below check before closing the modal on clicking the overlay

if (document.getSelection().type === "Range") {
    return;
}

@Ethan-Hill
Copy link

Same thing here, this seems like quite a big issue to have if someone is just interacting with the content.

@mattiusclay
Copy link

Same issue here, very simple install, clicking on certain areas of the "modal__container", close the modal down for me. It's triggering the overlay close even though I'm clicking within the modal, surely that's not right?

@JSFTI
Copy link

JSFTI commented Dec 20, 2022

I "solved" this by manually adding mousedown event listener to the overlay element.

onmousedown="event.target.classList.contains('modal-overlay') && MicroModal.close("MODAL-ID-HERE")"

The close function will only be triggered if current mousedown event target is the overlay element.
That modal-overlay is the class name for my modal overlay.

@heyflo
Copy link

heyflo commented Jun 27, 2023

👋 Hello here! One simple fix would be to have the overlay on its own. At the moment the content of the modal modal__container is nested inside the overlay which is listening for interaction(s) to close the modal. I tried it and it's working perfectly (using it myself). You just need to adjust your css to have the modal__container positioned correctly 😁 .

image

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

5 participants