question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Autocomplete] Requires two clicks to open on mobile ios after state is set

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When using a controlled autocomplete input, user clicks once to open the menu and selects a value. Then then click off the auto complete to elsewhere on the page. Then the click back on the autocomplete. It does not open. They have to click a second time and then it opens.

Expected Behavior 🤔

When using a controlled autocomplete input, user clicks once to open the menu and selects a value. Then then click off the auto complete to elsewhere on the page. Then the click back on the autocomplete. It opens.

Steps to Reproduce 🕹

https://codesandbox.io/s/romantic-meninsky-kcqgh and here is the code (from autocomplete docs):

/* eslint-disable no-use-before-define */
import React from "react";
import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";

const top100Films = [
  { title: "The Shawshank Redemption", year: 1994 },
  { title: "Inglourious Basterds", year: 2009 },
  { title: "Snatch", year: 2000 },
  { title: "3 Idiots", year: 2009 },
  { title: "Monty Python and the Holy Grail", year: 1975 }
];

function Playground() {
  const [value, setValue] = React.useState(null);

  return (
    <div style={{ width: 300 }}>
      <Autocomplete
        options={top100Films}
        openOnFocus
        getOptionLabel={option => option.title}
        id="controlled-demo"
        value={value}
        onChange={(event, newValue) => {
          setValue(newValue);
        }}
        renderInput={params => (
          <TextField {...params} label="controlled" margin="normal" />
        )}
      />
    </div>
  );
}

export default Playground;

Context 🔦

This will prevent me from using autocomplete componnent due to its effect on mobile users.

Your Environment 🌎

Tech Version
Material-UI v4.9.12
Material-UI Lab v4.0.0-alpha.53
React 16.13.1
Browser iOS Safari
TypeScript 3.8.3
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, May 16, 2020

@joshwooding Awesome. @kaplantm What do you think of this fix? Do you want to work on a pull request? 😃

diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
index ddb4f1d71..da2e010cf 100644
--- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
+++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
@@ -16,9 +16,14 @@ export { createFilterOptions };
 export const styles = (theme) => ({
   /* Styles applied to the root element. */
   root: {
-    '&:hover $clearIndicatorDirty, &$focused $clearIndicatorDirty': {
+    '&$focused $clearIndicatorDirty': {
       visibility: 'visible',
     },
+    // Avoid double tap issue on iOS
+    '@media (pointer: fine)': {
+      '&:hover $clearIndicatorDirty': {
+        visibility: 'visible',
+      },
+    },
   },
   /* Styles applied to the root element if `fullWidth={true}`. */
   fullWidth: {

We already use the fine media query for the date picker with @dmtrKovalenko in https://github.com/mui-org/material-ui-pickers/pull/1653.

0reactions
kaplantmcommented, May 16, 2020

@joshwooding Thanks for looking into this so quickly. I’m considering using this component in a project within the next couple weeks. Do you think there will be a quick fix / workaround or should I look into an alternative? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Autocomplete] Requires two clicks to open on mobile ios after ...
When using a controlled autocomplete input, user clicks once to open the menu and selects a value. Then then click off the auto...
Read more >
Autocomplete requires you to click twice in iOS after update to ...
After a set time, check to see if the autocomplete results are still visible. If they are, and an item is focussed, trigger...
Read more >
Autocomplete: Must click two times to select an item in iOS
First click on an item only sets class "ui-state-focus". Must click it again to actually select it. This worked in version 1.10.0.
Read more >
The Annoying Mobile Double-Tap Link Issue - CSS-Tricks
Here's two lines of CSS that will cause the problem​​ But clicking that link will not prevent the link from being visited. On...
Read more >
Change AutoFill settings in Safari on Mac - Apple Support
To change these settings, choose Safari > Settings, then click AutoFill. Complete forms with information from any contact card in Contacts. To view...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found