fix(getEnvironmentProps): remove obsolete check causing tap not to close #803
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue that made mobile users have to tap twice outside the autocomplete to close the panel.
The issue was caused by an obsolete check within the
isTargetWithinAutocomplete
flag. We were checking whether the current active element was contained within the form or the panel, as a way to ensure we weren't closing the panel when interacting with the autocomplete. However, this was problematic:event.target
is in the form or the panel.touchstart
, the current active element is the previous target (when it's a focusable element), so at this stage it was still the search input. This is why the panel was closing on second tap.touchstart.mov
Tests
I've updated the related test to better reflect user scenarios and catch the error. We were relying on the panel being initially opened (using
initialState
). In the test,document.activeElement
was alwaysbody
, and we never were in the scenario of having first opened the panel from a tap.Now, we first focus the search input, verify that the panel is open, then tap outside, and verify that the panel is closed. Without the fix, the second assertion doesn't pass.
I've also updated the other tests asserting what the active element was, because this causes false negatives (see explanation on
touchstart
behavior explained above).Next steps
I've moved the
@TODO
higher because the problem that occurs with multiple Autocomplete instances happens higher, at the state level (the first check is wrong). I'll open a separate issue for it.We'll also need to update the test suite for
onTouchMove
(I added a@TODO
).fixes #710