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

mWeb: Keep the focus state of the composer when closing three dots menu in report header #28899

Merged
merged 7 commits into from
Oct 18, 2023

Conversation

ginsuma
Copy link
Contributor

@ginsuma ginsuma commented Oct 5, 2023

Details

We no longer use the video chat button on the report header. We use the three dots menu instead. This PR keeps the focus state of the composer on mWeb when closing the three dots menu on the report header.

Fixed Issues

$ #26763
PROPOSAL: #26763 (comment)

Tests

  1. Open a chat report.
  2. Focus on the main composer.
  3. Tap the three dots icon.
  4. Tap outside the menu to exit.
  5. Verify that:
  • On Web and desktop, the main composer is unfocused.
  • On mWeb and native apps, the main composer is focused.
  1. Blur the main composer.
  2. Tap the three dots icon.
  3. Tap outside the menu to exit.
  4. Verify that the main composer is unfocused.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-10-09.at.1.21.13.PM.mov
Mobile Web - Safari
Screen.Recording.2023-10-09.at.1.34.42.PM.mov
Mobile Web - Chrome
Screen.Recording.2023-10-09.at.1.36.39.PM.mov
Desktop
Screen.Recording.2023-10-09.at.1.56.32.PM.mov
iOS
Screen.Recording.2023-10-09.at.1.21.52.PM.mov
Android
Screen.Recording.2023-10-09.at.3.45.19.PM.mov

@@ -273,6 +274,15 @@ function HeaderView(props) {
<ThreeDotsMenu
anchorPosition={styles.threeDotsPopoverOffset(props.windowWidth)}
menuItems={threeDotMenuItems}
shouldSetModalVisibility={false}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On mWeb, we focus on the main composer by the modal state. This led to the inconsistency between mWeb and native apps.

if (!(willBlurTextInputOnTapOutside && !isNextModalWillOpenRef.current && !modal.isVisible && isFocused && (prevIsModalVisible || !prevIsFocused))) {
return;
}
focus();

Comment on lines 278 to 285
onIconPress={() => {
const {composerRef, editComposerRef, isFocused, isEditFocused} = ReportActionComposeFocusManager;
if (isFocused()) {
composerRef.current.blur();
} else if (isEditFocused()) {
editComposerRef.current.blur();
}
}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On native apps, the composer doesn't blur when we click on buttons. We need to blur it by code like we did here

const onAddActionPressed = useCallback(() => {
if (!willBlurTextInputOnTapOutside) {
isKeyboardVisibleWhenShowingModalRef.current = composerRef.current.isFocused();
}
composerRef.current.blur();
}, []);

I also blurred the edit composer to make consistency between mWeb and native apps.

Copy link
Contributor

@ArekChr ArekChr Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ginsuma This change causes regression on mobile-web and native. When closing the modal, the composer doesn't re-focus in case when it was focused before. The issue is that when the composer was not focused, after opening and closing the modal, the composer shouldn't focus.

Copy link
Contributor Author

@ginsuma ginsuma Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArekChr I think whether the composer is focused or not if we open the three dots menu, the composer will blur. We only re-focus on some cases, like opening an emoji picker or adding actions.

But we also can restore the keyboard state if this is our expected behavior. On Desktop Web, we don't restore or keep the focus state when clicking on the three dots button.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we also can restore the keyboard state if this is our expected behavior

  • Remove onIconPress above.
  • Add onMouseDown={(e) => Browser.isMobile() && e.preventDefault()} to PressableWithoutFeedback in ThreeDotsMenu to keep the focus state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArekChr I will wait for your confirmation before pushing a new commit and recording new videos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pecanoro any thoughts? I think that the composer should be refocused when it was focused before, like on the emoji picker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing it and in any other case, if the composer was focused and we open any modal or menu, it get's refocused on going back, so we should do the same with the 3 dots!

@ginsuma ginsuma marked this pull request as ready for review October 5, 2023 09:50
@ginsuma ginsuma requested a review from a team as a code owner October 5, 2023 09:50
@melvin-bot melvin-bot bot requested review from ArekChr and removed request for a team October 5, 2023 09:50
@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

@ArekChr Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@ginsuma
Copy link
Contributor Author

ginsuma commented Oct 9, 2023

@ArekChr I updated the code to keep the focus state.

@ArekChr
Copy link
Contributor

ArekChr commented Oct 9, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mov
Mobile Web - Chrome
android.chrome.mov
Mobile Web - Safari
ios.safari.mov
Desktop
desktop.mov
iOS
Nagranie.z.ekranu.2023-10-11.o.10.26.41.mov
Android
Nagranie.z.ekranu.2023-10-11.o.10.27.22.mov

@ArekChr
Copy link
Contributor

ArekChr commented Oct 9, 2023

I can't test Android because of some build errors, will update video after fixing it

Copy link
Contributor

@ArekChr ArekChr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, it works on the mobile web, and nothing has changed on other platforms.

@melvin-bot melvin-bot bot requested a review from pecanoro October 9, 2023 13:08
@pecanoro
Copy link
Contributor

I mentioned in a comment that we should refocus the composer as we do for the other modals, but I see we just remove the focus completely.

@ginsuma
Copy link
Contributor Author

ginsuma commented Oct 10, 2023

I mentioned in a comment that we should refocus the composer as we do for the other modals, but I see we just remove the focus completely.

@pecanoro After closing the three-dots menu, we keep the focus state like before. Could you share with me which platform did you test?

@ArekChr
Copy link
Contributor

ArekChr commented Oct 11, 2023

@pecanoro I re-uploaded android and iOS recordings

@pecanoro
Copy link
Contributor

If the composer is focused, open the 3 dots modal and close it, the composer is not focused again.

Monosnap.screencast.2023-10-11.20-50-42.mp4

@ginsuma
Copy link
Contributor Author

ginsuma commented Oct 11, 2023

If the composer is focused, open the 3 dots modal and close it, the composer is not focused again.

@pecanoro I thought that was expected behavior on Web/Desktop. We have a similar menu, and we just remove the focus when opening/closing this menu on Web/Desktop. I keep the current behavior and update the mWeb behavior in this PR.
Screen Shot 2023-10-11 at 7 49 52 PM

But if we need to keep the focus state on these platforms, too. Which should we choose?

  1. The composer will still be focused when opening the three-dot menu. Users can type messages. This will be simple.
Screen Shot 2023-10-11 at 7 59 40 PM
  1. When we close the three-dots menu, we will focus on the main composer on all platforms as we did with Emoji Picker modal or Add Actions modal.
  2. The composer will be blurred when opening the menu and back to the previous focus state when closing the menu. We need to save the focus state of the main composer and the edit composer. Then, handling separately between Web/Desktop, mWeb, and native apps.

I'm looking forward to hearing your idea. Thanks!

@ArekChr
Copy link
Contributor

ArekChr commented Oct 12, 2023

@pecanoro The same behavior is on staging on the web and desktop platforms

@pecanoro
Copy link
Contributor

@pecanoro The same behavior is on staging on the web and desktop platforms

What do you mean by this?

I see two different behaviors with the other two modals:

  • Add actions: it seems to keep the state of whatever state was the composer before it was opened.
  • Emoji picker: it will focus the composer no matter what when closing it
  • Sny other menu that is not a modal and opens the LHN (profile, search, etc). It seems to refocus the composer when closed.

@ArekChr
Copy link
Contributor

ArekChr commented Oct 12, 2023

@pecanoro I mean that behavior on a web browser doesn't change compared to staging, The issue is to prevent focusing composer while opening and closing the dots modal, in the scenario when the composer was not focused before opening the modal on the mobile web

@ginsuma ginsuma changed the title Remove focus when closing three dots menu in report header Keep the focus state of the composer when closing three dots menu in report header Oct 12, 2023
@ginsuma ginsuma changed the title Keep the focus state of the composer when closing three dots menu in report header mWeb: Keep the focus state of the composer when closing three dots menu in report header Oct 12, 2023
@ginsuma
Copy link
Contributor Author

ginsuma commented Oct 17, 2023

@pecanoro, what is the next step here?

@pecanoro
Copy link
Contributor

I was doing some testing on mobile and it seems it's also pretty inconsistent, so we can leave it unfocused.

@@ -91,6 +96,12 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
onIconPress();
}
}}
onMouseDown={(e) => {
if (!Browser.isMobile()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last request, can you explain here why we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pecanoro, on Web and mWeb, the composer will blur if we click outside the text input. This is expected on Web, but not mWeb. On there, we want to keep the focus state like we did on native apps when closing the menu.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant is, can you add a comment in the code before the if condition explaining that? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pecanoro I added it.

@pecanoro pecanoro merged commit 44c90d3 into Expensify:main Oct 18, 2023
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/pecanoro in version: 1.3.87-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

1 similar comment
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/pecanoro in version: 1.3.87-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.87-12 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/pecanoro in version: 1.3.88-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 1.3.88-11 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants