reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component
MIT License
2.17k stars 532 forks source link

How can I handle non suggested terms? #338

Open carpben opened 6 years ago

carpben commented 6 years ago

I am looking for an autocomplete that can suggest options from a given list, but can also accept other options. However when I the AutoComplete component this property: onSelect={val => console.log(`selection val=${val}`)} And then in the browser I type into it and press enter, it will only call the function when there is a highlighted suggestion, and call it with the highlighted suggestion as an argument. Is there a way to use any term and with enter send that value?

carpben commented 6 years ago

It seems I can't pass the component an onKeyPress property, to handle an enter press case.

0xori commented 6 years ago

Hi, you can easily achieve this by using inputProps:

inputProps={{onKeyPress: (e)=>{
 if (e.key === 'Enter') {
  // do whatever
 }
}}}