App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-10-30] Esc key doesn't dismiss any of the `ConfirmModal` around the app

Open isagoico opened this issue 5 years ago • 34 comments

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:

  1. Navigate to a user.
  2. Add an attachment more than 50 MB.
  3. Expect "attachment too large" warning to pop up.
  4. 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 image

Upwork Job URL: https://www.upwork.com/jobs/~01ae467f5cc80cb019

Issue reported by: @rushatgabhane Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1631136254079800

View all open jobs on GitHub

isagoico avatar Sep 09 '21 15:09 isagoico

Triggered auto assignment to @TomatoToaster (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Sep 09 '21 15:09 MelvinBot

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:

parasharrajat avatar Sep 09 '21 15:09 parasharrajat

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.

TomatoToaster avatar Sep 09 '21 15:09 TomatoToaster

Ok I think the accessibility case (mentioned in slack) is a good enough case. I'm going to make this external officially.

TomatoToaster avatar Sep 09 '21 16:09 TomatoToaster

Triggered auto assignment to @trjExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Sep 09 '21 16:09 MelvinBot

Triggered auto assignment to @Luke9389 (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Sep 09 '21 22:09 MelvinBot

Proposal

  1. For the specific case of AttachmentModal we just need to pass the onCancel Callback which is called on the press of ESC. https://github.com/Expensify/App/blob/01f351c41f59c1c991d068dd0cecca2e34f17d11/src/components/AttachmentModal.js#L160
                    onCancel={this.closeConfirmModal}

  1. For other confimModals, we can quickly run a search to find all instances of ConfirmModal and attach the callback to reset the isVisible prop of ConfirmModal to its onCancal Callback.

parasharrajat avatar Sep 10 '21 12:09 parasharrajat

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.

rushatgabhane avatar Sep 10 '21 12:09 rushatgabhane

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.

parasharrajat avatar Sep 10 '21 13:09 parasharrajat

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.

parasharrajat avatar Sep 10 '21 13:09 parasharrajat

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.

Ohh okay, sounds good!

rushatgabhane avatar Sep 10 '21 13:09 rushatgabhane

If I do this:

  1. 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 isVisible and using componentDidupdate, Update this state property when isVisible prop changes.

    b. Then set the isVisible prop of Modal component to this.state.isVisible and set this state prop to false on onClose callback.

    <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 avatar Sep 10 '21 15:09 parasharrajat

@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?

rushatgabhane avatar Sep 10 '21 17:09 rushatgabhane

We will loop back around to this after the n6-hold is lifted

Luke9389 avatar Sep 21 '21 00:09 Luke9389

Still on hold, Melv.

trjExpensify avatar Sep 29 '21 21:09 trjExpensify

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.

kadiealexander avatar Oct 08 '21 01:10 kadiealexander

@Luke9389 Maybe you can review the proposal and I can submit a PR for it.

parasharrajat avatar Oct 08 '21 05:10 parasharrajat

Ping for @Luke9389

parasharrajat avatar Oct 08 '21 15:10 parasharrajat

Yup, didn't the n6 freeze was just for merges.

Luke9389 avatar Oct 08 '21 17:10 Luke9389

Yup, it's for merges but we can submit a PR based on the recent post from Matt. @Luke9389

parasharrajat avatar Oct 08 '21 17:10 parasharrajat