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

[HOLD for payment 2023-12-15] [$500] Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD #32294

Closed
1 of 6 tasks
lanitochka17 opened this issue Nov 30, 2023 · 30 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Nov 30, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.6-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

Prerequisite: Default currency is not set as USD for the workspace

  1. Login to ND Expensify
  2. Navigate to Workspace RHN panel
  3. Click "Bank account"
  4. In Workspace currency popup, Select Cancel via keyboard tab key and press Enter key

Expected Result:

Workspace currency popup is closed without any change to default currency

Actual Result:

Although user selects Cancel and presses Enter key via keyboard, default currency is updated to USD instead of closing the popup

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • Windows: Chrome
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6296333_1701367620093.2023-11-30_20-04-19.mp4

Bug6296333_1701367620069!cancel_default_currency

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a44752663555a980
  • Upwork Job ID: 1730293320039825408
  • Last Price Increase: 2023-11-30
  • Automatic offers:
    • dukenv0307 | Contributor | 27974587
Issue OwnerCurrent Issue Owner: @anmurali
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 30, 2023
@melvin-bot melvin-bot bot changed the title Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD [$500] Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD Nov 30, 2023
Copy link

melvin-bot bot commented Nov 30, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01a44752663555a980

Copy link

melvin-bot bot commented Nov 30, 2023

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

Copy link

melvin-bot bot commented Nov 30, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 30, 2023
Copy link

melvin-bot bot commented Nov 30, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ArekChr (External)

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.=

Pressing enter while focus on the Cancel button will update the currency to USD and close the modal.

What is the root cause of that problem?

In the workspace currency update modal, the Update to USD button has a pressToEnter props which will listen to enter key.

<Button
success={props.success}
danger={props.danger}
style={[styles.mt4]}
onPress={props.onConfirm}
pressOnEnter

So, even when we focus on the cancel button, the confirm button press is still triggered.

What changes do you think we should make in order to solve the problem?

Disable the pressToEnter if there is a cancel button.

pressOnEnter={!props.shouldShowCancelButton}

@paultsimura
Copy link
Contributor

paultsimura commented Nov 30, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Pressing enter while focusing on the "Cancel" button triggers the "Confirm" button action

What is the root cause of that problem?

We use pressOnEnter on the "Confirm" button in the confirmation modal.

<Button
success={props.success}
danger={props.danger}
style={[styles.mt4]}
onPress={props.onConfirm}
pressOnEnter
text={props.confirmText || translate('common.yes')}
isDisabled={isOffline && props.shouldDisableConfirmButtonWhenOffline}
/>

This triggers the button press when the "Enter" is pressed no matter what element was focused.

What changes do you think we should make in order to solve the problem?

While applying the pressOnEnter trigger on a Button, we use a specific validation to check whether to submit the button or allow the default event to be fired:

const keyboardShortcutCallback = useCallback(
(event?: GestureResponderEvent | KeyboardEvent) => {
if (!validateSubmitShortcut(isFocused, isDisabled, isLoading, event)) {
return;
}
onPress();
},
[isDisabled, isFocused, isLoading, onPress],
);

We should alter the logic that determines whether the above-mentioned pressOnEnter will fire:

const validateSubmitShortcut: ValidateSubmitShortcut = (isFocused, isDisabled, isLoading, event) => {
const eventTarget = event?.target as HTMLElement;
if (!isFocused || isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA') {
return false;
}
event?.preventDefault();
return true;
};

We are already checking if the focused element during pressing Enter is not a textarea (in that case we want to submit the form).
We should also check if the pressed element is not a pressable – and if it is, we'll want to disable the custom hotkey trigger, which will result in firing the default event – triggering the onPress of the focused pressable:

    const eventTarget = event?.target as HTMLElement;
-   if (!isFocused || isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA') {
+   if (!isFocused || isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA' || eventTarget.dataset.tag === 'pressable') {
        return false;
    }

Result:

Screen.Recording.2023-11-30.at.20.24.36-compressed.mp4

What alternative solutions did you explore? (Optional)

@dukenv0307
Copy link
Contributor

dukenv0307 commented Dec 1, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Selecting Cancel and pressing Enter key via keyboard updates default currency to USD

What is the root cause of that problem?

We pass pressOnEnter for confirm button and we don't check the active element before triggering onPress function when we press on enter key

if (!isFocused || isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA') {

if (!validateSubmitShortcut(isFocused, isDisabled, isLoading, event)) {

What changes do you think we should make in order to solve the problem?

We should check if the active element has role in the element like button, radio, checkbox, link,... we will not subscribe enter key listen for button

  1. Get activeElement from useActiveElement hook and create a variable like disableEnterShortcut which is true if role of active element is button, radio, ... We should check role instead of dataTag because some elements can have onPress event but dataTag isn't pressable i.e. TextLink
const activeElement = useActiveElement();
const arrayRole: string[] = Object.values(CONST.ACCESSIBILITY_ROLE);
const shouldDisableEnterShortcut = arrayRole.includes(activeElement.role) && activeElement.role !== CONST.ACCESSIBILITY_ROLE.TEXT;
  1. Update isActive here to isActive: pressOnEnter && !shouldDisableEnterShortcut, with this check, we don't need to subscribe enter key in button if active element is clickable element.

isActive: pressOnEnter,

OPTION: We can also update this condition in onSubmit function of FormSubmit by checking event.target.role to prevent submitting the form if we are focusing on an element that has onPress event.

  1. For now, I see we pass role props to Pressable, we should update here to role={(props.accessibilityRole ?? props.role) as Role}

role={props.accessibilityRole as Role}

What alternative solutions did you explore? (Optional)

We can check event.target.role in validateSubmitShortcut

@DylanDylann
Copy link
Contributor

DylanDylann commented Dec 1, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

  • Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD

What is the root cause of that problem?

  • Currently, with the "Confirm" button, we have prop pressOnEnter that leads to it will auto trigger onPress function once when pressing ENTER

<Button
success={props.success}
danger={props.danger}
style={[styles.mt4]}
onPress={props.onConfirm}
pressOnEnter
text={props.confirmText || translate('common.yes')}
isDisabled={isOffline && props.shouldDisableConfirmButtonWhenOffline}
/>

  • So when we focus on the "Cancel' button, and then press ENTER, it also trigger the "Confirm" button `s onPress

What changes do you think we should make in order to solve the problem?

  • In Slack, once the confirm modal is opened, it will auto-focus on the "Confirm" button for the first time. If we blur it out, so there is no component focused, pressing ENTER does not do anything.
  • So, we can do like Slack: Disable the pressing ENTER event listener and auto-focus on the "Confirm" for the first time. Do it by:
  1. First, create the useEffect that focuses on the confirm button in the first render in here:
    const confirmButtonRef = useRef(null);
    useEffect(() => {
        // Focus on the Confirm button when the component mounts
        if (confirmButtonRef.current) {
            confirmButtonRef.current.focus();
        }
    }, []);
  1. Then, update:

    to:
                        pressOnEnter={props.pressOnEnter}     // Can discuss when the pressOnEnter is true or false

What alternative solutions did you explore? (Optional)

  • NA

Result

Screencast.from.01-12-2023.17.54.51.webm

@melvin-bot melvin-bot bot added the Overdue label Dec 4, 2023
@rojiphil
Copy link
Contributor

rojiphil commented Dec 4, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

In the Workspace Currency confirmation dialog, when keyboard Tab key is used to bring focus on Cancel button and, then, Enter key is pressed, the workspace currency get’s reset to $. However, the currency should not have been reset as the Enter key is pressed when focus is still on the Cancel button. This is the problem we are trying to solve.

What is the root cause of that problem?

Here, we use ConfirmModal for the workspace currency confirmation dialog which, in turn, uses ConfirmContent with two buttons here to display the contents of the dialog.

Now, since we use pressOnEnter here for the Confirm button, this will subscribe for Enter key event here. Now, pressing the ENTER key will trigger the callback here. Since this callback does not have a way to differentiate between buttons, onPress here will get called for all visible buttons including Cancel button. This is the reason why the workspace currency gets reset even when Enter key is pressed on Cancel button.

What changes do you think we should make in order to solve the problem?

Since Button is PressableWithFeedback here, we can set nativeID and pass id to Button. Using id as a differentiating factor for buttons, we can, now, ignore the call to onPress if the callback for Enter key event does not match that of the Confirm button. The advantage of using this approach is that by just adding the nativeID, we have a generic implementation for buttons to ensure that the callback does not get called for unintended buttons.

  1. Set nativeID for the Confirm button like this here and here
                        <Button
+                           nativeID=“ConfirmButton"
                        />
  1. Next, check if the callback was called for an intended button id like below just before the onPress here. If not, we return and avoid the call to onPress.

         if( event?.target && (event?.target as Element).id !== nativeID) {
             return;
         }
    

We also need to add nativeID to ButtonProps here and also initialize the property to an empty string within function Button. Further, we need to pass nativeID to PressableWithFeedback here like this nativeID={nativeID}

What alternative solutions did you explore? (Optional)

@ArekChr
Copy link
Contributor

ArekChr commented Dec 4, 2023

@paultsimura understands the root cause, and the proposal delivered a working solution first.

🎀 👀 🎀 C+ reviewed

@melvin-bot melvin-bot bot removed the Overdue label Dec 4, 2023
Copy link

melvin-bot bot commented Dec 4, 2023

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

@situchan
Copy link
Contributor

situchan commented Dec 4, 2023

Did we start fixing keyboard accessibility issues?

@dukenv0307
Copy link
Contributor

@ArekChr Check data-tag isn't enough because for TextLink we don't have data-tag is pressable but it can be clickable.

@mountiny
Copy link
Contributor

mountiny commented Dec 4, 2023

@ArekChr what do you think of the concerns shared here before I pick the solution?

I think we can fix this specific issue

@ArekChr
Copy link
Contributor

ArekChr commented Dec 5, 2023

@dukenv0307 Could you elaborate? To what component does TextLink point to? We don't use it in ConfirmContent

@dukenv0307
Copy link
Contributor

@ArekChr We can fix this globally to avoid any issue like this. For example, in ReferralDetailsPage you can see the TextLink doesn't have dataTag so if we focus on this text and press enter the event on Got it button also triggers. If we check the role we can avoid this issue for any component not just ConfirmModal.

Screen.Recording.2023-12-05.at.16.46.01.mov

@ArekChr
Copy link
Contributor

ArekChr commented Dec 5, 2023

@dukenv0307 Thanks for the clarification! We should avoid further issues if the confirm modal has different elements rather than just checking the pressable tag. After rethinking, I've decided to approve @dukenv0307 proposal. This new approach will solve the problem in a better way. As you mentioned, it also helps us with other app parts, like the link button and elements like the radio button or checkbox, which do not exist yet.
🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Dec 5, 2023

Current assignee @mountiny is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@rojiphil
Copy link
Contributor

rojiphil commented Dec 5, 2023

@ArekChr @dukenv0307

I had a quick look at the approved proposal and have a query.
If we do not subscribe to the key events for elements with the mentioned accessibility roles (e.g. link, button), curious to know if keyboard shortcuts would work consistently on native devices for these elements. Or, just like the web, will the handlers be called in native devices also?

@dukenv0307
Copy link
Contributor

@rojiphil we will not subscribe to the enter key event of the button if the active element (focused element) has a role link, button, ... not do not subscribe to the key events for elements with the mentioned accessibility roles (e.g. link, button).

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 5, 2023
Copy link

melvin-bot bot commented Dec 5, 2023

📣 @dukenv0307 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@dukenv0307
Copy link
Contributor

@ArekChr The PR is ready for review.

@mountiny
Copy link
Contributor

mountiny commented Dec 6, 2023

Merged! thanks!

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 8, 2023
@melvin-bot melvin-bot bot changed the title [$500] Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD [HOLD for payment 2023-12-15] [$500] Web - Workspace - Selecting Cancel and pressing Enter key via keyboard updates default currency to USD Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.9-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-12-15. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 8, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@ArekChr] The PR that introduced the bug has been identified. Link to the PR:
  • [@ArekChr] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@ArekChr] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@ArekChr] Determine if we should create a regression test for this bug.
  • [@ArekChr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@anmurali] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Dec 14, 2023
Copy link

melvin-bot bot commented Dec 18, 2023

@anmurali, @ArekChr, @mountiny, @dukenv0307 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Dec 18, 2023
@mountiny
Copy link
Contributor

@ArekChr @dukenv0307 could you please handle the checklist before payment?

@ArekChr
Copy link
Contributor

ArekChr commented Dec 18, 2023

  • Link to the PR: No PR with bug identified. It seems this case was never handled
  • Link to comment: n/a
  • Link to discussion: n/a
  • Determine if we should create a regression test for this bug: We can add a regression test to ensure we keep good accessibility practices.

Regression test proposal

  1. Open App
  2. Navigate to the Workspace RHN panel
  3. Click "Bank account"
  4. Focus Cancel via the keyboard tab key in the Workspace currency popup and press Enter.
  5. Ensure that cancel was pressed instead of Delete (submitting form)

Do we agree 👍 or 👎

Copy link

melvin-bot bot commented Dec 19, 2023

@anmurali, @ArekChr, @mountiny, @dukenv0307 Huh... This is 4 days overdue. Who can take care of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

10 participants