App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2022-02-01] Pressing "Tab" key while the result list of AddressSearch is open leaves it open even after clicking outside

Open aldo-expensify opened this issue 5 years ago • 65 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Type an address that yield results
  2. Press "Tab" key
  3. Click somewhere else in the form

Expected Result:

The list of results should close after clicking outside Focused element of the list after pressing tab should be highlighted

Actual Result:

The list remains open event after focusing other inputs No element of the list gets highlighted even if the focus changed to one of them after pressing tab

https://user-images.githubusercontent.com/87341702/140454912-b4a5d533-105c-48ff-9dcf-68e491dc7058.mov

Workaround:

The user can still close the list by focusing again on the AddressSearch input and clicking outside. Or the user can just ignore the opened list.

Platform:

Where is this issue occurring?

  • Web
  • Desktop App

Version Number: Reproducible in staging?: Reproducible in production?: Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation Expensify/Expensify Issue URL: Issue reported by: Slack conversation:

View all open jobs on GitHub

aldo-expensify avatar Nov 05 '21 03:11 aldo-expensify

Triggered auto assignment to @flaviadefaria (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

MelvinBot avatar Nov 05 '21 03:11 MelvinBot

Triggered auto assignment to @Dal-Papa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Nov 05 '21 11:11 MelvinBot

Triggered auto assignment to @kevinksullivan (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Nov 05 '21 13:11 MelvinBot

@Dal-Papa, @kevinksullivan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

MelvinBot avatar Nov 08 '21 19:11 MelvinBot

Chill @MelvinBot, it was the weekend and we just started a company offsite.

Dal-Papa avatar Nov 08 '21 21:11 Dal-Papa

In AddressSearch.js file we have to:

  1. Add here onKeyPress prop https://github.com/Expensify/App/blob/d217777b51a48f35e029dae7e2395af76adce7cb/src/components/AddressSearch.js#L107
onKeyPress: (event) => {
                    if(event.code == 'Tab' && !isSelected){
                        googlePlacesRef.current.setAddressText("")
                    }
                },

to handle press "tab" button in input

  1. Add to AddressSearch component isSelected state variable with useState hook to check if user selected final address we will not clear input field but only will move to next input field. https://github.com/Expensify/App/blob/d217777b51a48f35e029dae7e2395af76adce7cb/src/components/AddressSearch.js#L41 const [isSelected, setIsSelected] = useState(true);

  2. Change this variable when user selects something from dropdown in onPress method of GooglePlacesAutocomplete Component: https://github.com/Expensify/App/blob/d217777b51a48f35e029dae7e2395af76adce7cb/src/components/AddressSearch.js#L91-L93

onPress={(data, details) => {
saveLocationDetails(details);
                setIsSelected(true)

  1. Add onBlur method of GooglePlacesAutocomplete Component to make list of results close after clicking outside: https://github.com/Expensify/App/blob/d217777b51a48f35e029dae7e2395af76adce7cb/src/components/AddressSearch.js#L86
onBlur={() => {
                    if(!isSelected){
                        googlePlacesRef.current.setAddressText("")
                    }}}

https://user-images.githubusercontent.com/71173662/141126429-741210e1-947d-41af-98b1-b79b47bf3f0d.mov

developvsn avatar Nov 10 '21 14:11 developvsn

@Dal-Papa, @kevinksullivan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

MelvinBot avatar Nov 12 '21 19:11 MelvinBot

https://www.upwork.com/jobs/~01324fec6df4ab30d9

kevinksullivan avatar Nov 12 '21 20:11 kevinksullivan

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

MelvinBot avatar Nov 12 '21 20:11 MelvinBot

I think @developvsn's proposal looks good, though I think it'd be event.key if we're matching to Tab and not the keyCode 9.

@kevinksullivan can you hire @developvsn for this job? Thanks!

NikkiWines avatar Nov 15 '21 20:11 NikkiWines

All set!

kevinksullivan avatar Nov 16 '21 00:11 kevinksullivan

@NikkiWines @kevinksullivan Hey ! I run into issue "doesn't have permission to make PR" Who i can reach out for some help?

2021-11-16 12 56 30

developvsn avatar Nov 16 '21 19:11 developvsn

@NikkiWines @kevinksullivan Hey ! I run into issue "doesn't have permission to make PR" Who i can reach out for some help?

2021-11-16 12 56 30

Did you fork the repo?

aldo-expensify avatar Nov 16 '21 19:11 aldo-expensify

Sorry I didn't look at this better before, but the implemented behaviour is not consistent with blur by clicking outside, and I think it is also not what is expected.

If you click outside, the autocomplete results disappear but the typed text remains there. On the other hand, if you press tab, it makes the autocomplete disappear and clears the typed text. This remains impossible to use using just the keyboard, you cannot select a result and selecting a result is mandatory.

https://user-images.githubusercontent.com/87341702/142887668-f3186a61-4383-4ab5-97d8-533997333173.mov

In my opinion, the expected behaviour should be to keep the list open and move the focus to the first result, and then the next result, etc, until you are out of the list. Related comment: https://github.com/Expensify/App/pull/6115#issuecomment-974913981

aldo-expensify avatar Nov 22 '21 15:11 aldo-expensify

@aldo-expensify the address field uses react-native google places autocomplete library and to remove focus from the list it requires to clear the entered text if we are using Tab because blur() and focus() ref methods don't work in this library, also we cannot use Tab to select any of addresses from the list dropdown because this library doesn't support this: we can't make onFocus blue border of any element from the list and if the user will press Enter it will trigger form submit.

User still can enter the address manually if clicks or selects with Tab the "Can't find your address? Enter it manually"

https://user-images.githubusercontent.com/71173662/143053991-d09262e0-3526-4402-b14f-e71b906377b8.mp4

developvsn avatar Nov 23 '21 16:11 developvsn

@aldo-expensify brings up a good point, especially in reference to accessibility. You would expect the tab to go to the next element in the list, not to skip to the next field.

Additionally, I agree that the behavior around clearing the address field should be consistent regardless of how the user removes focus from the field.

Since this change needs to be reverted anyway (the commits were unsigned - revert PR here) let's take this opportunity to get more consistent with our implementation, namely:

  1. Clicking away from the field should remove focus and close the search list, and maintain the contents of the input field
  2. Pressing tab should move the focus onto the next element in the search list, and maintain the contents of the input field.

Does that sound right, @aldo-expensify?

NikkiWines avatar Nov 23 '21 17:11 NikkiWines

Clicking away from the field should remove focus and close the search list, and maintain the contents of the input field Pressing tab should move the focus onto the next element in the search list, and maintain the contents of the input field.

I would like to point out that the lib currently does based on the code it has. I have gone through it. So there is some issue due to which the dropdown is not getting closed when the focus is moved out of the dropdown. @NikkiWines

parasharrajat avatar Nov 23 '21 17:11 parasharrajat

One other note that at the moment the accessibility comments are not considered actionable (for now), we're just testing the new process at this time - link

NikkiWines avatar Nov 23 '21 17:11 NikkiWines

In reality, the selected item is not highlighted when focused via Tab. The border should get blue as well as this issue should be fixed.

parasharrajat avatar Nov 23 '21 17:11 parasharrajat

@aldo-expensify brings up a good point, especially in reference to accessibility. You would expect the tab to go to the next element in the list, not to skip to the next field.

Additionally, I agree that the behavior around clearing the address field should be consistent regardless of how the user removes focus from the field.

Since this change needs to be reverted anyway (the commits were unsigned - revert PR here) let's take this opportunity to get more consistent with our implementation, namely:

  1. Clicking away from the field should remove focus and close the search list, and maintain the contents of the input field
  2. Pressing tab should move the focus onto the next element in the search list, and maintain the contents of the input field.

Does that sound right, @aldo-expensify?

Yep, agree with all that.

I would like to point out that the lib currently does based on the code it has. I have gone through it. So there is some issue due to which the dropdown is not getting closed when the focus is moved out of the dropdown.

I looked into this when I first created the issue, but I don't remember 100%. I know that the library has some mechanism to detect that the focus changed from the text input to an element of the list to avoid closing it. The library closes the result list when the text input looses focus, but it shouldn't close when the text input goes out of focus when the focus changes to a result.

I don't remember exactly now why, but I have a vague memory of debugging and seeing that the library doesn't handle properly the change of focus with tab. At the time I thought that this would be hard to solve without changing the library. I don't think I'll have time today to look at it in detail, but I could do it tomorrow or the day after tomorrow :P

aldo-expensify avatar Nov 23 '21 18:11 aldo-expensify