-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
Changing options asynchronously will with autoHighlight have weird behaviour with onHighlightChange when options are changed but coincidentally the length doesn't change. The onHighlightChange don't trigger, or the first item does not get highlighted properly.
The behaviour is normal if options length changes.
Expected behavior 🤔
With autoHighlight it should properly highlight first item on any options change including options.length , as well as triggering onHighlightChange.
Steps to reproduce 🕹
Steps:
- Asynchronously change options but does not change the length of the array with a slight delay
autoHighlightenabledonHighlightChangeset up to see what's being highlighted- Change input to see the first item does not get highlighted after a change
- Change input again to see the previous first item became the highlighted item
https://codesandbox.io/s/loving-cerf-d212pw
Context 🔦
I'm trying to use this to fetch options async on every input change, like google search. Using onHighlightedChange to track currently highlighted item and direct it to onKeyDown on the input component. I couldn't use onChange because I wanted to track other keys pressed with enter to open in a new tab or a new window.
Looking at the source code, this line and comment is suspicious:
https://github.com/mui/material-ui/blob/master/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js#L503
Your environment 🌎
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.