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

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

Closed
2 of 6 tasks
lanitochka17 opened this issue Dec 13, 2023 · 51 comments
Closed
2 of 6 tasks

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

lanitochka17 opened this issue Dec 13, 2023 · 51 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Dec 13, 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.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
@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 Dec 13, 2023
@melvin-bot melvin-bot bot 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 Dec 13, 2023
Copy link

melvin-bot bot commented Dec 13, 2023

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

Copy link

melvin-bot bot commented Dec 13, 2023

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

Copy link

melvin-bot bot commented Dec 13, 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 Dec 13, 2023
Copy link

melvin-bot bot commented Dec 13, 2023

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

@dukenv0307
Copy link
Contributor

dukenv0307 commented Dec 13, 2023

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()) {

@bernhardoj
Copy link
Contributor

bernhardoj commented Dec 13, 2023

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;
    }

@mananjadhav
Copy link
Collaborator

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

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Dec 17, 2023

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

@mallenexpensify
Copy link
Contributor

@jasperhuangg when you have a min can you review @bernhardoj 's proposal above?
#32970 (comment)

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

melvin-bot bot commented Dec 22, 2023

📣 @bernhardoj 🎉 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 📖

@melvin-bot melvin-bot bot removed the Overdue label Dec 22, 2023
@jasperhuangg
Copy link
Contributor

Sorry for the delay, NewDot deployer chore has taken a lot of time this week. Looks good to me, assigned!

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Dec 22, 2023
@bernhardoj
Copy link
Contributor

PR is ready

cc: @mananjadhav

@melvin-bot melvin-bot bot removed the Overdue label Apr 23, 2024
@melvin-bot melvin-bot bot added the Overdue label May 1, 2024
@anmurali
Copy link

anmurali commented May 6, 2024

@ntdiary will resume working on #29199
This issue is still blocked on #29199

@melvin-bot melvin-bot bot removed the Overdue label May 6, 2024
@melvin-bot melvin-bot bot added the Overdue label May 15, 2024
@jasperhuangg
Copy link
Contributor

Still blocked on #29199

@melvin-bot melvin-bot bot removed the Overdue label May 15, 2024
@melvin-bot melvin-bot bot added the Overdue label May 24, 2024
@mallenexpensify
Copy link
Contributor

@melvin-bot melvin-bot bot removed the Overdue label May 24, 2024
@ntdiary
Copy link
Contributor

ntdiary commented May 27, 2024

We split that large PR into several smaller ones. phase1 #35572 has already been merged, and phase2 #42423 is under review. :)

@jasperhuangg
Copy link
Contributor

@ntdiary Awesome! Sounds like a good idea to split up the PR. Thanks for the update.

@melvin-bot melvin-bot bot added the Overdue label Jun 4, 2024
@mallenexpensify
Copy link
Contributor

mallenexpensify commented Jun 5, 2024

Above merged so we're getting close

@melvin-bot melvin-bot bot removed the Overdue label Jun 5, 2024
@melvin-bot melvin-bot bot added the Overdue label Jun 13, 2024
@melvin-bot melvin-bot bot removed the Overdue label Jun 19, 2024
@mallenexpensify mallenexpensify added the retest-weekly Apply this label if you want this issue tested on a Weekly basis by Applause label Jun 19, 2024
@mallenexpensify mallenexpensify 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 Jun 19, 2024
@mallenexpensify
Copy link
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.

@melvin-bot melvin-bot bot added the Overdue label Jun 27, 2024
@jasperhuangg
Copy link
Contributor

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

@ntdiary
Copy link
Contributor

ntdiary commented Jul 2, 2024

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

@mallenexpensify mallenexpensify removed the retest-weekly Apply this label if you want this issue tested on a Weekly basis by Applause label Jul 3, 2024
@mallenexpensify
Copy link
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

@melvin-bot melvin-bot bot removed the Overdue label Jul 3, 2024
@ntdiary
Copy link
Contributor

ntdiary commented Jul 3, 2024

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

@mallenexpensify
Copy link
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
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
No open projects
Archived in project
Development

No branches or pull requests

8 participants