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

Close QR-modal on outside click #892

Merged
merged 2 commits into from
Jun 29, 2023

Conversation

owi92
Copy link
Member

@owi92 owi92 commented Jun 27, 2023

This closes the modal when clicked outside, but keeps the share menu open.
Closes #879

@owi92 owi92 added the changelog:user User facing changes label Jun 27, 2023
@github-actions github-actions bot temporarily deployed to test-deployment-pr892 June 27, 2023 06:23 Destroyed
Copy link
Member

@LukasKalbertodt LukasKalbertodt left a comment

Choose a reason for hiding this comment

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

The problem with this approach is that clicking inside the modal (e.g. on the QR code) also closes the modal, as "outside" is defined as "outside of ref". And ref is the share menu. So the whole modal overlay is outside.

I think I'd prefer it if the Modal would take a prop closeOnOutsideClick or something like that, which implements this logic inside Modal. This should probably default to false to not change the behavior of other modal uses.

@owi92
Copy link
Member Author

owi92 commented Jun 27, 2023

Weird. There are two things is a thing I'm rather puzzeled by and failed to debug.
- The Modal component already has some logic which I think is meant to close it on outside clicks. The onClick is on the outer div, which is providing the darkened background. But it somehow only triggers when clicked on the inner div that contains the modal itself. OK just figured this out... it's because of the FocusTrap I added a couple of months ago, that needs to wrap around the background as well... meaning I wasted some time by implementing another solution 🤦 This also means that the ConfirmationModals used to close on outside clicks as well, so maybe we should keep or rather revert to that behaviour? Though I still wonder about the second thing:

  • The Modal component also has some logic to close it when pressing Escape. This works on the ConfirmationModals, but not on the QR modal. It doesn't even log the event when pressing Escape. Any other keys do... I don't get it.
    Actually it seems that the whole share menu won't close on pressing Escape, unlike all the other Floating menus.

TLDR: There is some issue I haven't figured out but don't spend too much if any time debugging (I already did). Marking this as a draft for now.

@owi92 owi92 marked this pull request as draft June 27, 2023 16:15
@github-actions github-actions bot temporarily deployed to test-deployment-pr892 June 27, 2023 16:19 Destroyed
Copy link
Member

@LukasKalbertodt LukasKalbertodt left a comment

Choose a reason for hiding this comment

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

maybe we should keep or rather revert to that behaviour?

After testing it out, I think I like that it doesn't close on outside click for these confirmation modals. So I think the PR as is is good.

I investigated the escape thing. The problem is: the share menu does its own "open" state management and just passes open={state !== "closed"} to the floating. And since the floating cannot affect the state in ShareButton, nothing happens.
Since I already looked at it locally, I also implemented a fix: I added another prop to FloatingContainer: onClose. A function that is called when the floating container determines it wants to close. Will push in a sec.

@github-actions github-actions bot temporarily deployed to test-deployment-pr892 June 29, 2023 07:45 Destroyed
@owi92
Copy link
Member Author

owi92 commented Jun 29, 2023

Cool, thank you. I also narrowed it down to the "open" prop and made a fix (removing the "closed" state and using the trigger="click" prop for the FloatingContainer instead, which results in the same outcome as your change.

Unfortunately this came with another issue that is also present in your fix: Using escape to close the QR modal also closes the share menu, which I'd really prefer to stay open. Floating UI seems to do it's own thing with the escape key and I'm out of ideas on how to fix that.
Would you say this behaviour is ok?

@LukasKalbertodt
Copy link
Member

Cool, thank you. I also narrowed it down to the "open" prop and made a fix (removing the "closed" state and using the trigger="click" prop for the FloatingContainer instead, which results in the same outcome as your change.

Oh, I hope we didn't work in parallel all the time so that I wasted your work? But yeah, your approach is totally valid as well. I do think though that the "having the state management outside" use case will be inevitable in the future, so the onClose prop is still useful? Or do you prefer your solution?

Unfortunately this came with another issue that is also present in your fix: Using escape to close the QR modal also closes the share menu, which I'd really prefer to stay open. Floating UI seems to do it's own thing with the escape key and I'm out of ideas on how to fix that.
Would you say this behaviour is ok?

Yeah, I noticed this too. Honestly, I think it's fine. I also have no idea how to fix that and I don't think investing time is terribly useful as it's such a minor thing.
Further, it might even be useful in some cases where people just want to scan the QR code and then close both things.

@owi92
Copy link
Member Author

owi92 commented Jun 29, 2023

I do think though that the "having the state management outside" use case will be inevitable in the future, so the onClose prop is still useful?

Yeah I definitely agree, so let's merge this.
Also, I didn't really use that much time on the fix itself but rather the debugging and reading FloatingUI docs. So I wouldn't consider it wasted time.

@owi92 owi92 marked this pull request as ready for review June 29, 2023 08:42
@LukasKalbertodt LukasKalbertodt merged commit ae501d6 into elan-ev:master Jun 29, 2023
@owi92 owi92 deleted the qr-modal-outside-click branch March 4, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:user User facing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QR modal doesn't close when clicking outside of it
2 participants