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

Fix loose focus for Web/Desktop #16673

Merged
merged 12 commits into from
Mar 31, 2023

Conversation

narefyev91
Copy link
Contributor

@narefyev91 narefyev91 commented Mar 29, 2023

Details

Amount field loose focus clicking outside

Fixed Issues

$ #16511
$ #16511 (comment)

Tests

  1. Launch expensify app
  2. Login with any account
  3. Tap on the FAB button -> Send money
  4. Enter numbers
  5. Click outside of numpad
  6. Enter numbers
  • Verify that no errors appear in the JS console

Offline tests

Nothing needed

QA Steps

Platform specific steps:

Web/Desktop:

  1. Launch expensify app
  2. Login with any account
  3. Tap on the FAB button -> Send money
  4. Enter numbers
  5. Click outside of numpad

Expected result - amount input will not loose focus

mWeb:

  1. Launch expensify app
  2. Login with any account
  3. Tap on the FAB button -> Send money
  4. Enter numbers
  5. Click outside of numpad
  6. Enter numbers

Expected results - amount input will be automatically focused - new typed number will be shown

Native IOS, Android:

  1. Launch expensify app
  2. Login with any account
  3. Tap on the FAB button -> Send money
  4. Enter numbers
  5. Click outside of numpad

Expected result - amount input will not loose focus

  • 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 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 correct English and 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 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
8mb.video-ENB-55UJCUZI.mp4
Mobile Web - Chrome
android-web.mov
Mobile Web - Safari
ios-web.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mov

@narefyev91 narefyev91 requested a review from a team as a code owner March 29, 2023 13:59
@MelvinBot
Copy link

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@melvin-bot melvin-bot bot requested review from 0xmiros and mountiny and removed request for a team March 29, 2023 13:59
@MelvinBot
Copy link

@mountiny @0xmiroslav One of you needs to 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]

mountiny
mountiny previously approved these changes Mar 29, 2023
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Looking good, thanks, @narefyev91 I think we could improve the testing steps to also include what to verify by the QA team. Could you make the changes also platform specific.

@narefyev91
Copy link
Contributor Author

Looking good, thanks, @narefyev91 I think we could improve the testing steps to also include what to verify by the QA team. Could you make the changes also platform specific.

Sure - updated description based on platforms

mountiny
mountiny previously approved these changes Mar 30, 2023
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Looks good to me, all yours @0xmiroslav Thanks!

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

Just confirming this one:
#16673 (comment)

@narefyev91
Copy link
Contributor Author

Just confirming this one: #16673 (comment)

@0xmiroslav @mountiny resolved latest comment

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

Code looks good. Testing now.
@narefyev91 please pull from main

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

Bug? Split bill title is not selectable while input focus

@narefyev91
Copy link
Contributor Author

Bug? Split bill title is not selectable while input focus

Should it be selectable? oO

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

Should it be selectable?

It's selectable in production. Also when not focused

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

selectable.mov

@narefyev91
Copy link
Contributor Author

narefyev91 commented Mar 30, 2023

in that case input should loose focus if we interact with header? @0xmiroslav

@0xmiros
Copy link
Contributor

0xmiros commented Mar 30, 2023

in that case input should loose focus if we interact with header? @0xmiroslav

I am not quite sure but I think at least when interact with header title.
Anyone who wants to copy & paste "Split bill" text? 😄

@mountiny
Copy link
Contributor

Yeah we should mimic the behaviour in production

@narefyev91
Copy link
Contributor Author

in that case input should loose focus if we interact with header? @0xmiroslav

I am not quite sure but I think at least when interact with header title. Anyone who wants to copy & paste "Split bill" text? 😄

Ok, but not sure if it will be possible to still use onBlur handler - event from onBlur will not contain information about something which placed before text input in DOM tree.

@narefyev91
Copy link
Contributor Author

Yeah we should mimic the behaviour in production

@0xmiroslav @mountiny came to one more solution which mostly covering all possible cases and not make any flickering regressions as well, and make header selectable

                <View
                    nativeID={this.amountViewID}
                    onMouseDown={(event) => {
                        const relatedTargetId = lodashGet(event, 'nativeEvent.srcElement.id');
                        if (_.contains([this.amountViewID], relatedTargetId)) {
                            event.preventDefault();
                        }
                    }}

We add new nativeID, and indicate if some clicks exactly in the dark area, if yes and nativeID is equal to which section we clicked - we will not remove focus. Clicking on currency selector and button will not make any UI visual issues because both have nativeID and they will not be pass inside if condition.

@narefyev91
Copy link
Contributor Author

narefyev91 commented Mar 31, 2023

I think last solution made it complex. Is it just to fix losing focus when click numpad gaps? Any bad effect if we move this to wrapper? wrapper

we can move this only to this wrapper

<View onMouseDown={e => e.preventDefault()} style={[styles.w100, styles.justifyContentEnd, styles.pageWrapper]}>
                    {DeviceCapabilities.canUseTouchScreen()
                        ? (
                            <BigNumberPad
                                numberPressed={this.updateAmountNumberPad}
                                longPressHandlerStateChanged={this.updateLongPressHandlerState}
                            />
                        ) : <View />}

                    <Button
                        success
                        style={[styles.w100, styles.mt5]}
                        onPress={() => this.props.onStepComplete(this.state.amount)}
                        pressOnEnter
                        isDisabled={!this.state.amount.length || parseFloat(this.state.amount) < 0.01}
                        text={this.props.translate('common.next')}
                    />
                </View>

Not really sure why it's started to be complex, we have one function which will cover any case now, and will cover if we add any new component to this page, if anything on the page will be changed we will need to add e.preventDefault rather that controlling based on nativeIDs. Moving e.preventDefault is fixing corner case rather than general solution cc @0xmiroslav , @mountiny

@mountiny
Copy link
Contributor

Lets try to get this merged today, I would not worry about some complexity at this point :D

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 2023

if anything on the page will be changed we will need to add e.preventDefault

It's same we will need to add nativeID. So no perfect general solution

It was initially request from Vit to focus input when clicking on numpad item (if we loose focus between buttons)

So I agree with this and leave gap case as is for now.
So I think just reverting last commit should be fine.

@narefyev91
Copy link
Contributor Author

if anything on the page will be changed we will need to add e.preventDefault

It's same we will need to add nativeID. So no perfect general solution

It was initially request from Vit to focus input when clicking on numpad item (if we loose focus between buttons)

So I agree with this and leave gap case as is for now. So I think just reverting last commit should be fine.

but why do we need to rollback commit if a new one covers also possibility not loose focus between numbers and make flow working identical ?

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 2023

but why do we need to rollback commit if a new one covers also possibility not loose focus between numbers and make flow working identical ?

I know that works, but I feel like it's overkill. Any other part in our codebase which added multiple nativeIDs to handle such case?

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 2023

This is what I initially thought when I am assigned on this issue:
This area can be considered input area and when click any point inside it, focus input so user feels like this is entire input view. And don't care about rest views (i.e. header, next button)

Screenshot 2023-03-31 at 1 24 59 PM

Simulator Screen Shot - iPhone 14 Pro Max - 2023-03-31 at 13 25 22

@narefyev91
Copy link
Contributor Author

but why do we need to rollback commit if a new one covers also possibility not loose focus between numbers and make flow working identical ?

I know that works, but I feel like it's overkill. Any other part in our codebase which added multiple nativeIDs to handle such case?

Screenshot 2023-03-31 at 14 30 34

@narefyev91
Copy link
Contributor Author

@0xmiroslav @mountiny ok what would be the last step - i rollback last commit and we good to go?

@mountiny
Copy link
Contributor

ok what would be the last step - i rollback last commit and we good to go?

Would that mean clicking between the numpads on mobile will leave focus? If yes we should not do that, thats a major UX bad

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 2023

@0xmiroslav @mountiny ok what would be the last step - i rollback last commit and we good to go?

I vote this. @mountiny what do you suggest? It may depend on whether we should handle numpad gap cases or not.

@narefyev91
Copy link
Contributor Author

narefyev91 commented Mar 31, 2023

ok what would be the last step - i rollback last commit and we good to go?

Would that mean clicking between the numpads on mobile will leave focus? If yes we should not do that, thats a major UX bad

that means - that on mobile web - when user click between buttons - input will loose focus (if i revert that change)

@mountiny
Copy link
Contributor

Yes we dont want that, its easy to fat finger between the numbers and it will be bad UX if user will have to click back to the number

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 2023

Yes we dont want that, its easy to fat finger between the numbers and it will be bad UX if user will have to click back to the number

ok then let's go with current solution

@mountiny
Copy link
Contributor

So do not revert

@0xmiros
Copy link
Contributor

0xmiros commented Mar 31, 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 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 correct English and 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 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mov
Mobile Web - Chrome
mchrome.mov
Mobile Web - Safari
msafari-new.mov
Desktop
desktop.mov
iOS
ios.mp4
Android
android.mov

Last part of mChrome video: blurred when click offline view
This is edge case and I believe we don't need to take care of it

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Thank you both for getting this over the finish line

@mountiny mountiny merged commit 2905d1e into Expensify:main Mar 31, 2023
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.2.93-3 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Apr 3, 2023

🚀 Deployed to production by https://github.com/thienlnam in version: 1.2.93-4 🚀

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

@abdulrahuman5196
Copy link
Contributor

abdulrahuman5196 commented Jun 3, 2023

Unable to Remove Request/Send Money Instantly by Holding the Remove Button
This issue was caused by a series of changes of IOU Money Keypad files.
#15710
#16394
#16673

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.

6 participants