-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Chat / The escape key should close open modals #1039
Comments
Have offered to two contributors in Upwork |
Just checked the AttachmentModal file and we can extend it with a key press listener (will only register for platforms that support key press in this case 'ESCAPE') and register on Modal mount and remove listener and clean up on Modal close or unmount. Note that we will use a reusable helper object that will enable future key press listener registration on different components. |
I propose we use a key press listener as @code-fi proposed. However, I propose registering/deregistering the key press listener using functions passed to the This approach ensures the listener is only registered once the modal is opened. Assuming users won't attach files every single time they open the app, registering listeners as soon as the component is mounted may be unnecessary. |
After testing multiple solutions, I found registering/deregistering the key press listener using I registered the listeners during |
Thanks for the notes everyone!
@code-fi I'm curious to learn more about what you meant by this. We have a key press library that can be used to bind keypresses https://github.com/Expensify/Expensify.cash/blob/master/src/libs/KeyboardShortcut/index.js can we use this? Or was there something else in mind?
@henryrossiter I think it probably be fine to hook the listener into the component mounting/unmounting. We are using the library above to delegate events which I think just registers new callbacks instead of adding event listeners. So maybe it can help?
I do think it would be nice to have this at the So I would probably choose to place the logic here and have my keypress listener call |
@marcaaron yes implementation will be similar to the KeyboardShortcut approach but it includes the following checks;
|
Yeah, this makes sense. I implemented the listener at the |
@code-fi
If my understanding is correct, this is already happening in the noop implementation here https://github.com/Expensify/Expensify.cash/blob/master/src/libs/KeyboardShortcut/index.native.js
Can we modify the existing
So it does sound like this will be a component of some sort then? I think to keep this simple we may be better off just using the lifecycle methods instead of creating any helper components. While this is a good idea I'm not sure we need to do this yet. |
@henryrossiter Yep, apologies that could have been more clear on our part. The only modals we have are the attachment ones right now, but it's in scope since the issue reads
We'll be adding more modals soon so this would be great to tackle now if possible. Thanks! |
not a component but it works like the KeyboardShortcut property |
@marcaaron check this MR #1180 |
Reopening this to add a new scenario that's not working ESC doesn't close the new chat/new group modalExpected resultPressing the escape button should close the modal Actual resultEscape button does nothing Action Performed
PlatformIssue is confirmed on: Desktop ✔️ Build 1.0.22-1 From @quinthar: https://expensify.slack.com/archives/C01GTK53T8Q/p1618952591439200
|
Grabbing this one as it has not been triaged yet. |
If you haven’t already, check out our contributing guidelines for onboarding!
Platform - version:
Desktop, build 280
Action Performed (reproducible steps):
Test 1
Test 2
Expected Result:
All modals should be cancelled when the user presses the Escape key.
Actual Result:
The modal stays on the screen
Notes/Photos/Videos:
![102928813-6878ce80-4467-11eb-8aec-82c137cbf461](https://user-images.githubusercontent.com/24399930/102931150-d1fadc00-446b-11eb-8f9c-46880aa89eef.png)
view the job on Upwork here.
The text was updated successfully, but these errors were encountered: