Skip to content

[HOLD for payment 2024-04-25] [$500] [LOW] Request money - When amount is highlighted, clicking on the page does not deselect the text #36862

Closed

Description

@izarutskaya

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


Found when validating PR : #36463

Version Number: v1.4.43-0
Reproducible in staging?: Y
Reproducible in production?: N
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation:

Action Performed:

Pre-requisite: the user should be logged in.

  1. Initiate a manual money request.
  2. Enter the amount.
  3. Do a text selection.
  4. Click on any part of the request page.
  5. Verify the text is not deselected.

Expected Result:

The text should be deselected after clicking on the page.

Actual Result:

The text is not deselected, remains highlighted.

Workaround:

Unknown

Platforms:

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

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

Screenshots/Videos

Bug6385343_1708407498195.bandicam_2024-02-19_23-02-52-094.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01626cde7ff61398d1
  • Upwork Job ID: 1760234439347433472
  • Last Price Increase: 2024-03-13
Issue OwnerCurrent Issue Owner: @laurenreidexpensify

Activity

  1. added
    Daily
    Bug
    on Feb 20, 2024
  2. melvin-bot commented on Feb 20, 2024

    @melvin-bot

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

  3. izarutskaya commented on Feb 20, 2024

    @izarutskaya
    Author

    I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors.

    We think that this bug might be related to #vip-bills
    CC @davidcardoza

  4. Krishna2323 commented on Feb 20, 2024

    @Krishna2323
    Contributor

    Proposal

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

    Request money - When amount is highlighted, clicking on the page does not deselect the text

    What is the root cause of that problem?

    We call event.preventDefault(); in onMouseDown callback function, and due to this the text doesn't get deselected.

    const onMouseDown = (event, ids) => {
    const relatedTargetId = lodashGet(event, 'nativeEvent.target.id');
    if (!_.contains(ids, relatedTargetId)) {
    return;
    }
    event.preventDefault();

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

    Initial Proposal We should use `removeAllRanges` after calling `event.preventDefault();` in `onMouseDown`.

    This can be done using code below:

            if (window.getSelection) {
                window.getSelection().removeAllRanges();
            } else if (document.selection) {
                document.selection.empty();
            }

    PS: We shouldn't use setSelection when we use onMouseDown for following reasons:

    1. The default behaviour of the app/web is to blur the input when pressing outside and updating selection will focus instead of blurring the input.
    2. If half of the input value is selected then tapping outside will set selection will set the cursor to last text/number
    3. Unnecessary re-renders
    4. Inconsistency with the time input, in time input page we do blur the input and remove selection when pressing outside.

    Result

    text_selection_amount_form.mp4

    Alternative

    Remove event.preventDefault(); in onMouseDown.

    Optional

    The text selection is also not removed when we move to currency selection page and go back. For that we can use isFocused state and reset the selection to:

        useEffect(() => {
            if (!isFocused) {
                return;
            }
    
            setSelection({
                start: currentAmount.length,
                end: currentAmount.length,
            });
        }, [isFocused, setSelection]);

    Bug Video:

    bug_selection_2.mp4

    Alternative 2

    We can set selection start and end to selection.end after we prevent default.

            setSelection({
                start: selection.end,
                end: selection.end,
            });

    If we also want to fix the bug I mentioned in the optional section, we can do that like:

        useEffect(() => {
            if (!isFocused || wasFocused) {
                return;
            }
    
            setSelection({
                start: selection.end,
                end: selection.end,
            });
        }, [selection.end, isFocused, selection, wasFocused]);

    If we want the same behaviour on native devices also we need to wrap View with PressableWithoutFeedback execute the same functionality like onMouseDown when onPress in triggered.

    Demo Code
                <PressableWithoutFeedback
                    onMouseDown={(event) => {
                        onMouseDown(event, [AMOUNT_VIEW_ID]);
                    }}
                    style={[styles.moneyRequestAmountContainer, styles.flex1, styles.w100, styles.cursorDefault]}
                    accessibilityLabel="asda"
                    role={CONST.ROLE.NONE}
                    onPress={(event) => {
                        event?.stopPropagation();
                        event?.preventDefault();
                        if (selection.end === selection.start || !textInput.current?.isFocused()) {
                            return;
                        }
                        setSelection({
                            start: selection.end,
                            end: selection.end,
                        });
    
                        if (!textInput.current) {
                            return;
                        }
                        if (!textInput.current.isFocused()) {
                            textInput.current.focus();
                        }
                    }}
                >
                    <View
                        id={AMOUNT_VIEW_ID}
                        // style={[styles.w100, styles.justifyContentEnd, styles.pageWrapper, styles.pt0]}
                        style={[styles.moneyRequestAmountContainer, styles.flex1, styles.flexRow, styles.w100, styles.alignItemsCenter, styles.justifyContentCenter]}
                    >
                        <TextInputWithCurrencySymbol
                            formattedAmount={formattedAmount}
                            onChangeAmount={setNewAmount}
                            onCurrencyButtonPress={onCurrencyButtonPress}
                            placeholder={numberFormat(0)}
                            ref={(ref) => {
                                if (typeof forwardedRef === 'function') {
                                    forwardedRef(ref);
                                } else if (forwardedRef?.current) {
                                    // eslint-disable-next-line no-param-reassign
                                    forwardedRef.current = ref;
                                }
                                textInput.current = ref;
                            }}
                            selectedCurrencyCode={currency}
                            selection={selection}
                            onSelectionChange={(e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
                                if (!shouldUpdateSelection) {
                                    return;
                                }
                                const maxSelection = formattedAmount.length;
                                const start = Math.min(e.nativeEvent.selection.start, maxSelection);
                                const end = Math.min(e.nativeEvent.selection.end, maxSelection);
                                setSelection({start, end});
                            }}
                            onKeyPress={textInputKeyPress}
                            isCurrencyPressable
                        />
                        {!!formError && (
                            <FormHelpMessage
                                style={[styles.pAbsolute, styles.b0, styles.mb0, styles.ph5, styles.w100]}
                                isError
                                message={formError}
                            />
                        )}
                    </View>
                </PressableWithoutFeedback>

    Result

    fix_amount_selection.mp4
  5. davidcardoza commented on Feb 20, 2024

    @davidcardoza
    Contributor

    Adding to the vip bill pay project board as a LOW issue

  6. changed the title [-] Request money - When amount is highlighted, clicking on the page does not deselect the text[/-] [+][LOW] Request money - When amount is highlighted, clicking on the page does not deselect the text[/+] on Feb 20, 2024
  7. added
    External
    on Feb 21, 2024
  8. changed the title [-][LOW] Request money - When amount is highlighted, clicking on the page does not deselect the text[/-] [+][$500] [LOW] Request money - When amount is highlighted, clicking on the page does not deselect the text[/+] on Feb 21, 2024
  9. melvin-bot commented on Feb 21, 2024

    @melvin-bot
  10. added
    Help Wanted
    on Feb 21, 2024
  11. 88 remaining items

  12. melvin-bot commented on Apr 25, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@laurenreidexpensify)

    • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1760234439347433472/hired)
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  13. laurenreidexpensify commented on Apr 26, 2024

    @laurenreidexpensify
    Contributor

    Payment Summary:

    Contributor: $500 @Krishna2323 paid in upwork
    C+: $500 @situchan to be paid in Upwork

    steps to complete when @situchan is back from OOO in May:

    • payment
    • regression steps
  14. situchan commented on May 17, 2024

    @situchan
    Contributor

    @laurenreidexpensify Sorry for late. Can you please send new offer?

  15. laurenreidexpensify commented on May 20, 2024

    @laurenreidexpensify
    Contributor

    @situchan offer sent in upwork 👍

  16. laurenreidexpensify commented on May 21, 2024

    @laurenreidexpensify
    Contributor

    Payment Summary:

    Contributor: $500 @Krishna2323 paid in upwork
    C+: $500 @situchan paid in upwork

  17. laurenreidexpensify commented on May 21, 2024

    @laurenreidexpensify
    Contributor

    @situchan can you confirm regression testing steps so we can close out thanks

  18. situchan commented on May 21, 2024

    @situchan
    Contributor

    Regression Test Proposal

    1. Initiate a manual money request
    2. Enter the amount
    3. Do a text selection
    4. Click on any part of the request page
    5. Verify the text is deselected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyEngineeringInternal

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions