olahol / react-tagsinput

Highly customizable React component for inputing tags.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Select autocomplete suggestion using keyboard not working

dboris opened this issue · comments

Using the autocomplete example on example/index.html, if you type the first few letters of a state and then use the down arrow key to choose the state and press Enter to select it, the actual tag created is not the suggestion, but the letters typed so far. Selecting the state suggestion with the mouse works as expected.

I had the same problem, my current workaround is something like this:

let handleOnChange = (event, {newValue, method}) => {
        if(method === 'enter') {
          event.preventDefault()
        } else {
          props.onChange(event)
        }
      }

return (
        <Autosuggest
          inputProps={{...other, onChange: handleOnChange}}
          otherFields...
        />
      )

Then I had to change react-tagsinput itself and add this snippet on the beggining of the handleKeyDown function:

if (e.defaultPrevented)
          return

Everything seems to be working now.

commented

I've added @mrbongiolo fix to version 3.13.2. I've also fixed the broken auto suggest example in example/index.js. Thanks guys.