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(getEnvironmentProps): remove obsolete check causing tap not to close #803

Merged
merged 5 commits into from
Oct 29, 2021

Conversation

sarahdayan
Copy link
Member

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:

  • We're already verifying this with the first check by assessing whether the event.target is in the form or the panel.
  • On 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 always body, 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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 28, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b7273f5:

Sandbox Source
zealous-mayer-k4kv0 Issue #710

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

The change seems to be working well on my mobile.

@@ -37,6 +37,8 @@ export function getPropGetters<
// outside of the autocomplete elements.
// This ensures a working experience on mobile because we blur the input
// on touch devices when the user starts scrolling (`touchmove`).
// @TODO: support cases where there are multiple Autocomplete instances.
// Right now, a second instance makes this computation return false.
onTouchStart(event) {
if (
store.getState().isOpen === false ||
Copy link
Member

@francoischalifour francoischalifour Oct 29, 2021

Choose a reason for hiding this comment

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

I wonder if the check below is even required:

event.target === inputElement

It could be the source of the multi-instance bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure. From my tests it came from the state being wrong, but indeed this check could be useless. We'll check that.

@sarahdayan sarahdayan merged commit 51cfb94 into next Oct 29, 2021
@sarahdayan sarahdayan deleted the fix/double-tap-to-close branch October 29, 2021 10:48
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.

Requires double tap to close
2 participants