[HOLD for payment 2021-10-30] Esc key doesn't dismiss any of the `ConfirmModal` around the app
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Navigate to a user.
- Add an attachment more than 50 MB.
- Expect "attachment too large" warning to pop up.
- Press Escape key.
Expected Result:
Escape should close the ConfirmModal
Actual Result:
Escape doesn't do anything.
Workaround:
User has to close the modal manually
Platform:
Where is this issue occurring?
- Web
- Desktop App
Version Number: 1.0.95-0
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Upwork Job URL: https://www.upwork.com/jobs/~01ae467f5cc80cb019
Issue reported by: @rushatgabhane Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1631136254079800
Triggered auto assignment to @TomatoToaster (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Sorry for pitching in but IMO ConfirmModal should not be escaped. Their purpose is to be confirmed by the user so whatever action is mentioned on the modal should be confirmed by the user.
In this case User should click close. In other cases for example when money is transferred and the user is asked to confirm something, he should choose among the presented buttons.
Or we can change this behavior. :smile_cat:
Hmm I'm personally fine with it escaping the modal with escape key. Let's ping the room and see if we can get a larger consensus on this before implementing it.
Ok I think the accessibility case (mentioned in slack) is a good enough case. I'm going to make this external officially.
Triggered auto assignment to @trjExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Triggered auto assignment to @Luke9389 (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
Proposal
- For the specific case of AttachmentModal we just need to pass the
onCancelCallback which is called on the press ofESC. https://github.com/Expensify/App/blob/01f351c41f59c1c991d068dd0cecca2e34f17d11/src/components/AttachmentModal.js#L160
onCancel={this.closeConfirmModal}
- For other confimModals, we can quickly run a search to find all instances of
ConfirmModaland attach the callback to reset theisVisibleprop of ConfirmModal to itsonCancalCallback.
onCancel={this.closeConfirmModal}
@parasharrajat you wanna pass an additional prop to ConfirmModal? But that'd also add an extra button which isn't needed.
Also, we'll have to define and pass a callback everytime we use ConfirmModal. This is not very "DRY".
Do you think we can do better? So that this behaviour is built-in for the component?
Maybe something with the help of navigation.
Ahh, I didn't see it through that it will render the button. Absolutely, we can inbuild it in the ConfirmModal if we just want to hide every ConfirmModal. I will update the Proposal to add that as well.
I just checked onCancel does not show an extra button until shouldShowCancelButton is true but You made a good point that we can just push this code inside the ConfirmModal.
I just checked
onCanceldoes not show an extra button untilshouldShowCancelButtonis true but You made a good point that we can just push this code inside the ConfirmModal.
Ohh okay, sounds good!
If I do this:
-
If we want to close all confirmModals when Esc is pressed and don't want to manage it from the Parent Component. Then we can
a. Add a state property
isVisibleand usingcomponentDidupdate, Update this state property whenisVisibleprop changes.b. Then set the isVisible prop of Modal component to
this.state.isVisibleand set this state prop tofalseononClosecallback.
<Modal
onClose={() => {
this.setState({isVisible: false});
props.onCancel();
});
isVisible={this.state.isVisible}
type={props.isSmallScreenWidth
? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED
: CONST.MODAL.MODAL_TYPE.CONFIRM}
>
There is an issue with this @rushatgabhane. As ConfirmModal is controlled by the isVisible state of the parent component, we have to set it to false whenever the modal is closed. Otherwise, next time, ConfirmModal will not be shown as isVisible was already true.
e.g.
onCancel={this.closeConfirmModal}
is necessary.
Then we still need to pass a callback to reset the parent Component state. Thus my first proposal stands correct.
Can you think of a way to mitigate this? If so, let me know.
@parasharrajat I get why it's a problem. And I don't have a better solution.
I'll throw some ideas, but I don't want to waste your time.
Umm some clever design pattern could do the trick. Or, instead of using a prop to make it visible, navigate to the modal so you can "go back". Onyx?
We will loop back around to this after the n6-hold is lifted
Still on hold, Melv.
Please refer to this post for updated information on the n6 hold, we've raised the bonus to $250 for all issues where a PR is created before the N6 hold is lifted.
@Luke9389 Maybe you can review the proposal and I can submit a PR for it.
Ping for @Luke9389
Yup, didn't the n6 freeze was just for merges.
Yup, it's for merges but we can submit a PR based on the recent post from Matt. @Luke9389