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] autoHighlight not working properly for asynchronous requests

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 typing a query into an asynchronous Autocomplete before the request finishes loading, Autocomplete with autoHighlight set to true does not highlight the first option. Only after pressing another key do first options get highlighted as they should. Everything then works as expected until the user clears the textfield and starts over.

Expected Behavior 🤔

The first option should be selected when the request finishes loading.

Steps to Reproduce 🕹

Steps:

  1. Go to https://codesandbox.io/s/material-demo-ycmz7?file=/demo.tsx
  2. Click on the textfield and quickly type a letter such as “a” before the request finishes loading
  3. You will see that “Portugal” is not selected even though autoHighlight is on
  4. Type another letter and you’ll see that first options are selected as they should
  5. Delete (backspace) the input and type another letter and you see that everything works as it should
  6. Leave the textfield by clicking away or hitting escape. When you start at step 2 you’ll see the bug again.

Your Environment 🌎

I just upgraded from v4.0.0-alpha.50 where this bug did not yet exist. So something must have changed in the recent merges.

Tech Version
Material-UI Lab v4.0.0-alpha.53
React 16.13.1
Browser Chrome
TypeScript 3.9.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
marcosvega91commented, May 16, 2020

I leave the resolution to @mstykow that has discovered the bug, otherwise I can do it. It’s ok for your resolution but I think that in both cases a test case is needed 😄

1reaction
mstykowcommented, May 14, 2020

Nice. Maybe one more improvement simplifying your if statement:

if (!loading && filteredOptions.length) {
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Autocomplete] autoHighlight not working properly for ... - GitHub
When typing a query into an asynchronous Autocomplete before the request finishes loading, Autocomplete with autoHighlight set to true does ...
Read more >
How to use onchange with autocomplete material ui?
The handleChange function in turn calls setLocation which updates the location state with the new value.
Read more >
React Autocomplete component - Material UI - MUI
The component supports two different asynchronous use-cases: Load on open: it waits for the component to be interacted with to load the options....
Read more >
Autocomplete Search Using Material UI and API - YouTube
AutoComplete #React #ArslanHow's it going y'all in today's video we're gonna learn how to create an auto-complete text field using Material ...
Read more >
Directives > mdAutocomplete - AngularJS Material
Parameter Type Description md‑search‑text expression expression A model to bind the search query text to. md‑selected‑item object object A model to bind the selected item...
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