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

Prevent clicks originating inside modal from dismissing #36603

Closed
wants to merge 1 commit into from

Conversation

Sentox6
Copy link

@Sentox6 Sentox6 commented Jun 19, 2022

Current behaviour means any click events on the modal backdrop will dismiss the dialog, regardless of whether the initial mousedown event originated inside the dialog. When the modal contains elements such as text inputs, it's quite easy to accidentally close it by (for example) clicking and dragging to select text; if the mouse is released over the backdrop, the modal will close.

This change uses an event handler for mousedown and mouseup, and tracks whether a mousedown began outside the dialog or not.

Current behaviour means any click events on the modal backdrop will dismiss the dialog, regardless of whether the initial mousedown event originated inside the dialog. When the modal contains elements such as text inputs, it's quite easy to accidentally close it by (for example) clicking and dragging to select text; if the mouse is released over the backdrop, the modal will close.

This change uses an event handler for mousedown and mouseup, and tracks whether a mousedown began outside the dialog or not.
@Sentox6 Sentox6 requested a review from a team as a code owner June 19, 2022 08:16
@GeoSot
Copy link
Member

GeoSot commented Jun 20, 2022

Thank you a lot @Sentox6
Maybe is duplicated of #36401?

@Sentox6
Copy link
Author

Sentox6 commented Jun 20, 2022

Thank you a lot @Sentox6 Maybe is duplicated of #36401?

Definitely addressing the same issue; however, perhaps one drawback of only using a mouse-down event is that the user cannot avoid dismissing the modal by moving the mouse back inside the dialog before releasing their click. It may create the reverse issue where (for example) the user tries to select some text in the modal, and if their click starts just outside, it will dismiss immediately.

I generally prefer behaviour that doesn't trigger until mouseup, too, but that's just my opinion.

@GeoSot
Copy link
Member

GeoSot commented Jun 21, 2022

Really thank you for your quick response here. 💯
I am going to merge the #36401 as it adds the proper tests, facing the already open issue, and in any case I'll keep this solution, in my mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants