Skip to content

[Due for payment 2025-04-14] [$250] Search - Pasting long text removes left padding & cursor focus is missing #58214

Closed

Description

@vincdargento

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: V9.1.11-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): Slottwo1+ffggggfd@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10s android 13
App Component: Search

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Tap the Search icon at the top
  3. Paste a short text into the search input
  4. Observe that the text has proper left padding, and the focus is on the cursor
  5. Remove the text
  6. Paste a long text into the search input

Expected Result:

The left padding should be consistent for both short and long pasted text.

After pasting long text, the focus should remain on the cursor.

Actual Result:

Pasting short text maintains proper left padding and keeps focus on the cursor.

Pasting long text removes left padding, making the text stick to the left margin.

Cursor focus is missing, requiring the user to scroll to bring it into view.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021899895633486475589
  • Upwork Job ID: 1899895633486475589
  • Last Price Increase: 2025-03-12
  • Automatic offers:
    • thelullabyy | Contributor | 106609870
Issue OwnerCurrent Issue Owner: @mananjadhav

Activity

  1. added
    Bug
    Daily
    on Mar 11, 2025
  2. melvin-bot commented on Mar 11, 2025

    @melvin-bot

    Triggered auto assignment to @isabelastisser (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.

  3. nyomanjyotisa commented on Mar 11, 2025

    @nyomanjyotisa
    Member

    🚨 Edited by proposal-police: This proposal was edited at 2025-03-11 13:47:54 UTC.

    Proposal

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

    Pasting long text removes left padding & cursor focus is missing

    What is the root cause of that problem?

    We apply styles.pl3 on inputStyle instead of textInputContainerStyles

    and don't apply any padding right on textInputContainerStyles

    textInputContainerStyles={[styles.borderNone, styles.pb0]}
    inputStyle={[inputWidth, styles.pl3, {lineHeight: undefined}]}

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

    Apply both padding left and right (padding horizontal) on textInputContainerStyles

    and remove styles.pl3 from inputStyle

                            textInputContainerStyles={[styles.borderNone, styles.pb0, styles.ph3]}
                            inputStyle={[inputWidth, {lineHeight: undefined}]}

    Additionally, if we want to address the cursor focus issue, we can use InputUtils.scrollToRight to scroll to the right whenever the cursor is at the end of the input text

        const [cursorSelection, setCursorSelection] = useState<{start: number; end: number}>({start: 0, end: 0});
        const handleSelectionChange = (e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
            setCursorSelection(e.nativeEvent.selection);
        };
    
        useEffect(() => {
            if (ref && typeof ref !== 'function' && ref.current) {
                const input = ref.current as HTMLInputElement;
                if (cursorSelection.end === value.length) {
                    scrollToRight(input);
                }
            }
        }, [value, cursorSelection, ref]);

    and we should add onSelectionChange={handleSelectionChange} to the text input as well

                        <TextInput
                            ...
                            textInputContainerStyles={[styles.borderNone, styles.pb0, styles.ph3]}
                            inputStyle={[inputWidth, {lineHeight: undefined}]}
                            ...
                            onSelectionChange={handleSelectionChange}
                        />

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    None

    What alternative solutions did you explore? (Optional)

    New-Expensify.mp4
  4. thelullabyy commented on Mar 12, 2025

    @thelullabyy
    Contributor

    Proposal

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

    Pasting short text maintains proper left padding and keeps focus on the cursor.

    What is the root cause of that problem?

    When text is pasted into the InputComponent, the paste callback from useHtmlPaste is executed.

    const paste = useCallback(
    (text: string) => {
    try {
    const textInputHTMLElement = textInputRef.current as HTMLElement;
    if (textInputHTMLElement?.hasAttribute('contenteditable')) {
    insertAtCaret(textInputHTMLElement, text, maxLength);
    } else {
    const htmlInput = textInputRef.current as unknown as HTMLInputElement;
    const availableLength = maxLength - (htmlInput.value?.length ?? 0);
    htmlInput.setRangeText(text.slice(0, availableLength));
    }

    Copied content is added to the text field only at the position where the cursor is currently located without automatically scrolling to the new cursor position.

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

    Add this logic to calculate current position of the cursor and auto scroll input that position.

    requestAnimationFrame(() => {
                        const selection = window.getSelection();
                        if (selection && selection.rangeCount > 0) {
                            const range = selection.getRangeAt(0);
                            const caretRect = range.getBoundingClientRect();
                            const inputRect = textInputHTMLElement.getBoundingClientRect();
    
                            // Calculate position need to scroll to
                            const scrollLeft = Math.max(0, 
                                caretRect.left - inputRect.left + textInputHTMLElement.scrollLeft - textInputHTMLElement.clientWidth / 2
                            );
                            const scrollTop = Math.max(0, 
                                caretRect.top - inputRect.top + textInputHTMLElement.scrollTop - textInputHTMLElement.clientHeight / 2
                            );
    
                            // Auto scroll to the position of cursor
                            textInputHTMLElement.scrollLeft = scrollLeft;
                            textInputHTMLElement.scrollTop = scrollTop;
                        }
                    });
    

    This solution not only solve the problem of the paste action with Input Search on this screen but also in all other screen which use InputComponent

    With the left padding we've already have a PR here Text in search input, bounces with every letter added to the search to set opacity of the loading so we don't need add more padding and when we autoscroll with above logic, padding left will be correct

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    NA

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. added
    External
    Help Wanted
    on Mar 12, 2025
  6. melvin-bot commented on Mar 12, 2025

    @melvin-bot
  7. changed the title [-]Search - Pasting long text removes left padding & cursor focus is missing[/-] [+][$250] Search - Pasting long text removes left padding & cursor focus is missing[/+] on Mar 12, 2025
  8. melvin-bot commented on Mar 12, 2025

    @melvin-bot

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

  9. isabelastisser commented on Mar 12, 2025

    @isabelastisser
    Contributor

    Hi @mananjadhav, can you please review the proposals above? Thanks!

  10. mananjadhav commented on Mar 13, 2025

    @mananjadhav
    Collaborator

    I think we have similar solution of adding scrollToRight during the search. @nyomanjyotisa's proposal looks better to me.

    🎀 👀 🎀 C+ reviewed

  11. 26 remaining items

  12. removed
    Reviewing
    on Apr 7, 2025
  13. melvin-bot commented on Apr 7, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.23-7 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 2025-04-14. 🎊

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

  14. melvin-bot commented on Apr 7, 2025

    @melvin-bot

    @mananjadhav @isabelastisser @mananjadhav The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. added
    Daily
    and removed
    Weekly
    on Apr 14, 2025
  16. isabelastisser commented on Apr 15, 2025

    @isabelastisser
    Contributor

    BugZero Checklist:

    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • @mananjadhav 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:

    • @mananjadhav If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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:

    • @mananjadhav If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal Template
    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    Do we agree 👍 or 👎

  17. isabelastisser commented on Apr 15, 2025

    @isabelastisser
    Contributor

    Payment summary:

    @mananjadhav requires payment through NewDot Manual Request. $250 for C+ review
    @thelullabyy paid in Upwork automatic offer (Contributor)$250 for proposal

  18. isabelastisser commented on Apr 15, 2025

    @isabelastisser
    Contributor

    @mananjadhav, please complete the BZ checklist. Thanks!

  19. mananjadhav commented on Apr 19, 2025

    @mananjadhav
    Collaborator

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] 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: Couldn't pinpoint an exact offending PR. This was a problem for all the inputs on a specific platform.

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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: NA

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    I think it makes sense to add the regression test as it relates to a common component.

    Regression Test Proposal

    Test:

    1. Open Ap
    2. Tap the Search icon at the top
    3. Paste a short text into the search input
    4. Observe that the text has proper left padding, and the focus is on the cursor
    5. Remove the text
    6. Paste a long text into the search input
    7. Verify the focusing cursor remains visible at the end of the pasted text and the left padding is consistent for both short and long pasted text.

    Do we agree 👍 or 👎

    @isabelastisser ^

  20. garrettmknight commented on Apr 22, 2025

    @garrettmknight
    Contributor

    $250 approved for @mananjadhav

  21. isabelastisser commented on Apr 22, 2025

    @isabelastisser
    Contributor

    All set!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions