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

[$125] Taxes - BNP input is not auto focused in add rate page #51543

Open
2 of 8 tasks
lanitochka17 opened this issue Oct 27, 2024 · 26 comments
Open
2 of 8 tasks

[$125] Taxes - BNP input is not auto focused in add rate page #51543

lanitochka17 opened this issue Oct 27, 2024 · 26 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Overdue

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 27, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.54-0
Reproducible in staging?: Y
Reproducible in production?: N
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5134453
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch New Expensify app
  2. Go to workspace settings > Taxes
  3. Tap Add rate
  4. Tap Value

Expected Result:

BNP input will be auto focused

Actual Result:

BNP input is not auto focused

Workaround:

Unknown

Platforms:

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

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6647125_1730008681078.ScreenRecording_10-27-2024_13-52-22_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021850971328621900159
  • Upwork Job ID: 1850971328621900159
  • Last Price Increase: 2024-11-11
Issue OwnerCurrent Issue Owner: @Ollyws
@lanitochka17 lanitochka17 added the DeployBlockerCash This issue or pull request should block deployment label Oct 27, 2024
Copy link

melvin-bot bot commented Oct 27, 2024

Triggered auto assignment to @thienlnam (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

Copy link
Contributor

👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

Copy link

melvin-bot bot commented Oct 27, 2024

💬 A slack conversation has been started in #expensify-open-source

@lanitochka17
Copy link
Author

Production:

RPReplay_Final1730050554.MP4

@Krishna2323
Copy link
Contributor

Krishna2323 commented Oct 28, 2024

Edited by proposal-police: This proposal was edited at 2024-10-28 15:51:43 UTC.

Proposal


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

Taxes - BNP input is not auto focused in add rate page

What is the root cause of that problem?

  • I don't think this is caused by any recent PR.
  • We aren't focusing the input when the modal is visible.

<AmountForm
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
autoFocus
value={currentValue}
onInputChange={setValue}
/>

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


  • To focus on the amount input whenever the modal is set to visible we should use the same method as we do in

    const inputRef = useRef<BaseTextInputRef | null>(null);
    const inputValueRef = useRef(value);
    const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
    const inputCallbackRef = (ref: BaseTextInputRef | null) => {
    inputRef.current = ref;
    };

    useFocusEffect(
    useCallback(() => {
    focusTimeoutRef.current = setTimeout(() => {
    if (inputRef.current && isVisible) {
    inputRef.current.focus();
    (inputRef.current as TextInputType).setSelection?.(inputValueRef.current?.length ?? 0, inputValueRef.current?.length ?? 0);
    }
    return () => {
    if (!focusTimeoutRef.current || !isVisible) {
    return;
    }
    clearTimeout(focusTimeoutRef.current);
    };
    }, CONST.ANIMATED_TRANSITION);
    }, [isVisible]),
    );

    <InputWrapper
    ref={inputCallbackRef}

  • We should add the following in AmountSelectorModal.

    // Store the ref of the input
    const inputRef = useRef<BaseTextInputRef | null>(null);
    const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);

    const inputCallbackRef = (ref: BaseTextInputRef | null) => {
        inputRef.current = ref;
    };

    // use "useFocusEffect" focus on the input whenever "isVisible" state is changed.
    useFocusEffect(
        useCallback(() => {
            focusTimeoutRef.current = setTimeout(() => {
                if (inputRef.current && isVisible) {
                    inputRef.current.focus();
                }
                return () => {
                    if (!focusTimeoutRef.current || !isVisible) {
                        return;
                    }
                    clearTimeout(focusTimeoutRef.current);
                };
            }, CONST.ANIMATED_TRANSITION);
        }, [isVisible, inputRef]),
    );
    
    // Pass the ref to "AmountForm"
    ref={(ref) => inputCallbackRef(ref)}
  • We also need to remove the autoFocus prop.

What alternative solutions did you explore? (Optional)

Result

tax_amount_not_focused.mp4

@Beamanator
Copy link
Contributor

@Krishna2323

I don't think this is caused by any recent PR.

But then wouldn't that mean that the issue should be reproducible in prod?

@Beamanator Beamanator added Daily KSv2 and removed DeployBlockerCash This issue or pull request should block deployment Hourly KSv2 labels Oct 28, 2024
@Beamanator
Copy link
Contributor

I'm going to call this NAB - also I don't know if we need it to look "focused" - pressing numbers works fine

@Krishna2323
Copy link
Contributor

@Beamanator, I tried again to look for a recent PR that might have caused this issue, but I don’t believe any recent PR is responsible—though I may be wrong here. In my opinion, the root cause is the use of the autoFocus prop, which doesn’t always work. In all other components, we use inputCallbackRef from the useAutoFocusInput hook, and the same component is then focused correctly.

<InputWrapper
label={translate('iou.amount')}
InputComponent={AmountForm}
inputID={INPUT_IDS.MAX_EXPENSE_AMOUNT}
currency={CurrencyUtils.getCurrencySymbol(policy?.outputCurrency ?? CONST.CURRENCY.USD)}
defaultValue={defaultValue}
isCurrencyPressable={false}
ref={inputCallbackRef}

<InputWrapperWithRef
InputComponent={AmountForm}
inputID={INPUT_IDS.RATE}
fixedDecimals={CONST.MAX_TAX_RATE_DECIMAL_PLACES}
isCurrencyPressable={false}
currency={currency}
ref={inputCallbackRef}

I think we need to fix this to be consistent will all other similar pages:

Inconsistency

tax_amount_not_focused_issue.mp4

@thienlnam thienlnam added the External Added to denote the issue can be worked on by a contributor label Oct 28, 2024
@melvin-bot melvin-bot bot changed the title Taxes - BNP input is not auto focused in add rate page [$250] Taxes - BNP input is not auto focused in add rate page Oct 28, 2024
Copy link

melvin-bot bot commented Oct 28, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 28, 2024
Copy link

melvin-bot bot commented Oct 28, 2024

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

@thienlnam thienlnam changed the title [$250] Taxes - BNP input is not auto focused in add rate page [$125] Taxes - BNP input is not auto focused in add rate page Oct 28, 2024
Copy link

melvin-bot bot commented Oct 28, 2024

Upwork job price has been updated to $125

@Ollyws
Copy link
Contributor

Ollyws commented Nov 1, 2024

Reproducible, but also I agree with:

But then wouldn't that mean that the issue should be reproducible in prod?

What was the cause here?

Copy link

melvin-bot bot commented Nov 4, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Nov 4, 2024
Copy link

melvin-bot bot commented Nov 4, 2024

@Ollyws, @thienlnam Whoops! This issue is 2 days overdue. Let's get this updated quick!

@thienlnam thienlnam added the Bug Something is broken. Auto assigns a BugZero manager. label Nov 5, 2024
Copy link

melvin-bot bot commented Nov 5, 2024

Triggered auto assignment to @garrettmknight (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@melvin-bot melvin-bot bot removed the Overdue label Nov 5, 2024
@thienlnam
Copy link
Contributor

Let's get a fix up at this point - @Ollyws can you review the proposal?

@QichenZhu
Copy link
Contributor

The root cause is likely from upstream, as this happens only after enabling Bridgeless mode, but adding a delay as @Krishna2323 suggested might be the quickest option for now.

@Ollyws
Copy link
Contributor

Ollyws commented Nov 6, 2024

Ok if we're already using the proposed approach in TextSelectorModal then let's go with @Krishna2323's proposal.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Nov 6, 2024

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

Copy link

melvin-bot bot commented Nov 11, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Nov 11, 2024
Copy link

melvin-bot bot commented Nov 12, 2024

@garrettmknight, @Ollyws, @thienlnam Huh... This is 4 days overdue. Who can take care of this?

@garrettmknight garrettmknight moved this to Bugs and Follow Up Issues in [#whatsnext] #expense Nov 12, 2024
@thienlnam
Copy link
Contributor

Hmm, actually we shouldn't be adding setTimeouts here - I'm not sure how that other approach made it into the codebase. That doesn't address the root cause of the issue

@Krishna2323
Copy link
Contributor

Krishna2323 commented Nov 12, 2024

@thienlnam, using setTimeout is very common in cases where we need to focus on the input multiple times when the screen remains open, but a modal is opening and closing (AmountForm is a modal). We even use setTimeout in the useAutoFocusInput hook.

useImperativeHandle(innerRef, () => ({
focus() {
inputValidateCodeRef.current?.focus();
},
focusLastSelected() {
if (!inputValidateCodeRef.current) {
return;
}
if (focusTimeoutRef.current) {
clearTimeout(focusTimeoutRef.current);
}
focusTimeoutRef.current = setTimeout(() => {
inputValidateCodeRef.current?.focusLastSelected();
}, CONST.ANIMATED_TRANSITION);
},
}));
useFocusEffect(
useCallback(() => {
if (!inputValidateCodeRef.current) {
return;
}
if (focusTimeoutRef.current) {
clearTimeout(focusTimeoutRef.current);
}
focusTimeoutRef.current = setTimeout(() => {
inputValidateCodeRef.current?.focusLastSelected();
}, CONST.ANIMATED_TRANSITION);
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, []),
);

useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
setIsScreenTransitionEnded(true);
}, CONST.ANIMATED_TRANSITION);
return () => {
setIsScreenTransitionEnded(false);
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, []),
);

Monosnap ProcessMoneyRequestHoldPage tsx — App 2024-11-13 03-37-19

@thienlnam
Copy link
Contributor

We can update this form so it's consistent with the rest, but it's still a workaround. Ideally we'd solve this upstream for all of these cases and remove them, however not something we need to do in this issue

Copy link

melvin-bot bot commented Nov 14, 2024

@garrettmknight, @Ollyws, @thienlnam 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@Krishna2323
Copy link
Contributor

however not something we need to do in this issue

@thienlnam can get assigned then? This also requires an effect to focus on input every time we close the amount modal, so that's isn't an an upstream issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Overdue
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests

7 participants