[HOLD for payment 2022-02-01] Pressing "Tab" key while the result list of AddressSearch is open leaves it open even after clicking outside
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:
- Type an address that yield results
- Press "Tab" key
- 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:
Triggered auto assignment to @flaviadefaria (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.
Triggered auto assignment to @Dal-Papa (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Triggered auto assignment to @kevinksullivan (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@Dal-Papa, @kevinksullivan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Chill @MelvinBot, it was the weekend and we just started a company offsite.
In AddressSearch.js file we have to:
- Add here
onKeyPressprop 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
-
Add to
AddressSearchcomponentisSelectedstate variable withuseStatehook 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#L41const [isSelected, setIsSelected] = useState(true); -
Change this variable when user selects something from dropdown in
onPressmethod ofGooglePlacesAutocompleteComponent: https://github.com/Expensify/App/blob/d217777b51a48f35e029dae7e2395af76adce7cb/src/components/AddressSearch.js#L91-L93
onPress={(data, details) => {
saveLocationDetails(details);
setIsSelected(true)
- Add
onBlurmethod ofGooglePlacesAutocompleteComponent 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
@Dal-Papa, @kevinksullivan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
https://www.upwork.com/jobs/~01324fec6df4ab30d9
Triggered auto assignment to @NikkiWines (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
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!
All set!
@NikkiWines @kevinksullivan Hey ! I run into issue "doesn't have permission to make PR" Who i can reach out for some help?

@NikkiWines @kevinksullivan Hey ! I run into issue "doesn't have permission to make PR" Who i can reach out for some help?
Did you fork the repo?
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 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
@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:
- 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.
Does that sound right, @aldo-expensify?
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
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
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.
@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:
- 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.
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