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

Only close modal if directly clicking on backdrop #3884

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mary-ext
Copy link
Contributor

@mary-ext mary-ext commented May 7, 2024

Fixes #1894
Fixes #3834

This seemed to work for checking where the click/press initially started from, we don't want any clicks that initially started from the modal to be handled by the backdrop (which closes the modal)

@mary-ext
Copy link
Contributor Author

mary-ext commented May 7, 2024

Only deals with the old modals at the moment, which is fine, since the issue is with the profile edit modal. Let me see if there's a good way of doing this with the new modals, I think the right path might just be to expose a private API over the modal context

const onPressMask = (ev: React.MouseEvent<HTMLDivElement>) => {
// 1. Ignore clicks from inside the modal
// 2. Ignore clicks that started inside the modal and ended in the mask
if (ev.target !== ev.currentTarget.firstChild || clickInsideRef.current) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any solution that relies on timing here (like with tracking pointer down/up) seems suspicious to me. For this type of problem it's usually sufficient to check whether one node contains the other node.

What is special that requires this?

Copy link
Contributor Author

@mary-ext mary-ext May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this doesn't seem the right approach I think, now that I've tested it again this actually swallows clicks to backdrop if I attempt to do the second case.

Copy link
Contributor Author

@mary-ext mary-ext May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it seems that Headless UI does more or less the same thing to check where the click initially started. Perhaps it might be worthwhile to copy this hook over.

https://github.com/tailwindlabs/headlessui/blob/2d5d35a5337154e823767291637634b69b09ab94/packages/%40headlessui-react/src/hooks/use-outside-click.ts#L106-L149

The problem this PR tries to fix can be illustrated here:

2024-05-07.09-18-56.mp4

It's very easy to overshoot the mouse cursor when selecting text, and while a confirmation modal would've removed accidentally losing your changes, it doesn't really remove the annoyance issue that overshooting causes.

I believe it might be partly why the composer doesn't do backdrop clicks?

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