reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I handle non suggested terms?

carpben opened this issue · comments

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?

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

Hi,
you can easily achieve this by using inputProps:

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