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
Fix modal outside click bug when start inside and drag to outside #2890
Fix modal outside click bug when start inside and drag to outside #2890
Conversation
We've migrated from use-click-outside hook to overlay events because it does not work correctly with elements that are rendered within portal, for example |
Ah, I didn't know that. However there should be a way to solve the issue. It's very annoying to have closing modal on selecting text and move mouse down outside. |
There is not a good way to support all use cases, current implementation provides good balance between UX and DX |
Hi, I'm experiencing the same problem - would it be possible to somehow choose the implementation using a prop, for example? |
The use case described in this PR make sense (i.e. a click starting inside the modal, and finishing outside, should not close the modal). But I agree that the solution for now causes other issues while trying to solve this one. One way this could be solved, even though it can look a bit hacky, is by following the mouse actions of the user through a mutable ref. The gist of it would be:
This works because in the case of Modal, mouseup will always fire on the overlay, even when the click was contained inside the modal content. The slight delay for setting ref to false is because mouseup will actually fire before click, so we need to skip a frame. A simple |
@rtivital , let me know if you are open to my suggestion above 🙂 we have some users complaining about this issue, so we would really enjoy a fix! @hamitaksln , you can play around with my suggestion and update this PR if you'd like, otherwise I can also work on a separate PR if you prefer |
I've tried your PR and everything seems to be working fine. |
Yep, I saw it afterwards and it's indeed a better implementation 👍 |
Currently, on modal if you start mouse down inside modal and mouse down outside it closes modal and it's super annoying. I've tried to solve it with
use-click-outside
hook and seems it works just fine.