Skip to content

[$500] Compose Box - Focus not lost from composer on LHN popup open #32970

Closed

Description

@lanitochka17

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.11-6
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:

  1. Open the app
  2. Open any report and send any message
  3. Focus on composer
  4. Click on plus besides the composer to open Actions popup
  5. Right on any chat in LHN to open popup on LHN
  6. Observe that even though popup is open in LHN, app still focuses on composer

Expected Result:

App should not focus back on composer whenever any popup is open

Actual Result:

App focuses back on composer when we open actions popup and open any right click popup in LHN

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

Add any screenshot/video evidence

Bug6310077_1702365494694.windows_chrome_-_focus_back_cursor_issue.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0123ed583fdc5774f0
  • Upwork Job ID: 1734947870117650432
  • Last Price Increase: 2023-12-13
  • Automatic offers:
    • bernhardoj | Contributor | 28067465
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Dec 13, 2023
  2. changed the title [-] Compose Box - Focus not lost from composer on LHN popup open[/-] [+][$500] Compose Box - Focus not lost from composer on LHN popup open[/+] on Dec 13, 2023
  3. melvin-bot commented on Dec 13, 2023

    @melvin-bot

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

  4. melvin-bot commented on Dec 13, 2023

    @melvin-bot
  5. melvin-bot commented on Dec 13, 2023

    @melvin-bot

    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
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Dec 13, 2023
  7. melvin-bot commented on Dec 13, 2023

    @melvin-bot

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

  8. dukenv0307 commented on Dec 13, 2023

    @dukenv0307
    Contributor

    Proposal

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

    App focuses back on composer when we open actions popup and open any right click popup in LHN

    What is the root cause of that problem?

    When popover is closed, onPopoverMenuClose is called.

    And then restoreKeyboardState is called which makes the composer focused.

    const restoreKeyboardState = useCallback(() => {

    We already the logic here to blur the active element but the time this function is called, the active element isn't composer.

    if (DomUtils.getActiveElement()) {

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

    We should pass event to onPopoverMenuClose and pass it to onMenuClosed. And then in restoreKeyboardState, we should check if the event.target is a clickable element, we will not focus the composer.

    What alternative solutions did you explore? (Optional)

    We can add InteractionManager.runAfterInteractions here to wait the composer focus and then blur it.

    if (DomUtils.getActiveElement()) {

  9. bernhardoj commented on Dec 13, 2023

    @bernhardoj
    Contributor

    Proposal

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

    The composer is focused if we close the add action popover by opening another popover.

    What is the root cause of that problem?

    Every time the add action popover closes, we call restoreKeyboardState which will refocus the keyboard.

    const restoreKeyboardState = useCallback(() => {
    if (!isKeyboardVisibleWhenShowingModalRef.current || isNextModalWillOpenRef.current) {
    return;
    }
    focus();
    isKeyboardVisibleWhenShowingModalRef.current = false;
    }, []);

    When we right-click the LHN item or chat report message, it will:

    1. Close the add action popover
    2. Open the lhn or report popover
    3. Refocus the composer

    The composer focus will call focusComposerWithDelay

    const focus = useCallback((shouldDelay = false) => {
    focusComposerWithDelay(textInputRef.current)(shouldDelay);
    }, []);

    In focusComposerWithDelay, we already have a logic to prevent the focus from happening if the emoji picker is visible. That's why this doesn't happen when we open the emoji picker and then open the report popover.

    return (shouldDelay = false) => {
    // There could be other animations running while we trigger manual focus.
    // This prevents focus from making those animations janky.
    if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
    return;
    }

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

    Don't focus if the report/LHN popover is visible. Both use the same component, PopoverReportActionContextMenu.

    1. Expose a new variable from PopoverReportActionContextMenu called isVisible
      useImperativeHandle(ref, () => ({
      showContextMenu,
      hideContextMenu,
      showDeleteModal,
      hideDeleteModal,
      isActiveReportAction,
      instanceID,
      runAndResetOnPopoverHide,
      clearActiveReportAction,
      contentRef,
      }));
    isVisible: isPopoverVisible
    
    1. In focusComposerWithDelay, early return if PopoverReportActionContextMenu.isVisible() is true.
    import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu';
    
    if (!textInput || EmojiPickerAction.isEmojiPickerVisible() || ReportActionContextMenu.isVisible()) {
        return;
    }
    

    What alternative solutions did you explore? (Optional)

    I notice that this also happens if we:

    1. Open add action (+) popover
    2. Press the three-dots menu
    3. The composer will be focused

    To solve this for all popover, we can prevent the focus if any of the popover is showing.

    To do that, in ComposerWithSuggestions, get the popover context visible state.

    const {isOpen} = React.useContext(PopoverContext);
    
    const focus = useCallback((shouldDelay = false) => {
        if (isOpen) {
            return;
        }
    
  10. mananjadhav commented on Dec 17, 2023

    @mananjadhav
    Collaborator

    I liked @bernhardoj's proposal to fix this with ComposerWithSuggestions's popover context visible state.

    🎀 👀 🎀 C+ reviewed

  11. 96 remaining items

  12. added
    retest-weeklyApply this label if you want this issue tested on a Weekly basis by Applause
    on Jun 19, 2024
  13. changed the title [-][HOLD #29199] [$500] Compose Box - Focus not lost from composer on LHN popup open[/-] [+][$500] Compose Box - Focus not lost from composer on LHN popup open[/+] on Jun 19, 2024
  14. mallenexpensify commented on Jun 19, 2024

    @mallenexpensify
    Contributor

    The PR we were holding on closed without being fixed. I threw a retest-weekly on here to see if the bug exists six months later.

  15. jasperhuangg commented on Jul 1, 2024

    @jasperhuangg
    Contributor

    @mallenexpensify @lanitochka17 Are we still retesting this on weekly cadence?

  16. ntdiary commented on Jul 2, 2024

    @ntdiary
    Contributor

    This bug still exists. I remember there was another PR that added a focus trap feature, which confines the focus within the popover(or RHP?), but it seems to be ineffective in this situation. 🤔

    test.mp4
  17. removed
    retest-weeklyApply this label if you want this issue tested on a Weekly basis by Applause
    on Jul 3, 2024
  18. mallenexpensify commented on Jul 3, 2024

    @mallenexpensify
    Contributor

    @jasperhuangg retests take a weekish. @ntdiary and I are both able to reproduce so the bug still exists. I think we need to decide between

    1. Close it cuz it's a minor bug that doesn't affect functionality (I might actually prefer to be able to type and have the text fill the compose box vs nothing happening if I type)
    2. Review existing proposals to see if we want to accept any
    3. Add Help Wanted to get more proposals
    4. Something.

    I don't think we need/want to increase the price though

  19. ntdiary commented on Jul 3, 2024

    @ntdiary
    Contributor

    I remember our app has an interesting feature: even if the main input box isn't focused, pressing the keyboard will still automatically focus it, allowing for smooth typing. 😄

    demo.mp4
  20. mallenexpensify commented on Jul 5, 2024

    @mallenexpensify
    Contributor

    Thanks @ntdiary , I'm going to close, comment/reopen if you disagree.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions