Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material ui Autocomplete - select 'first entry' on Enter click

I have an autocomplete with options - which is an array of objects (Movies). My goal is when user types, e.g., he types "in" and then hits the Enter, that it selects first entry from the rendered list. In this case would be - 'Inception'. See screenshot. I found work around to select first entry by selecting first element from the rendered list. But I use createFilterOptions which makes it impossible.

Any suggestions?

https://codesandbox.io/s/material-demo-forked-cwcql?file=/demo.js

enter image description here

like image 896
Mykyta Avatar asked Jun 10 '26 20:06

Mykyta


1 Answers

Add the autoHighlight={true} prop to the <Autocomplete> component.

https://material-ui.com/api/autocomplete/#main-content

https://codesandbox.io/s/material-demo-forked-dh9b3?file=/demo.js

like image 116
wrxsti Avatar answered Jun 12 '26 12:06

wrxsti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!