[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:
- Go to https://codesandbox.io/s/material-demo-ycmz7?file=/demo.tsx
- Click on the textfield and quickly type a letter such as “a” before the request finishes loading
- You will see that “Portugal” is not selected even though
autoHighlight
is on - Type another letter and you’ll see that first options are selected as they should
- Delete (backspace) the input and type another letter and you see that everything works as it should
- 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:
- Created 3 years ago
- Comments:14 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 😄
Nice. Maybe one more improvement simplifying your if statement: