react-autosuggest icon indicating copy to clipboard operation
react-autosuggest copied to clipboard

onChange not fired when user presses Enter

Open hillc5 opened this issue 8 years ago • 1 comments

Description

when a user types a suggestion, highlights an option with up/down keys, then presses enter, the selection should trigger the onChange method in the inputProps object, as referenced here: https://www.npmjs.com/package/react-autosuggest#inputpropsonchange-required

CodePen: https://codepen.io/CharlesHill/pen/gBRzoq

Reproduction Steps

  1. Open Dev Tools on Codepen
  2. Type c, and wait for suggestions to appear
  3. Press Down to highlight selection
  4. Preass Enter to select

Observed behaviour: Nothing happens and nothing logs to the console

Expected behaviour: onChange should be called and 'enter' should be logged to the console

hillc5 avatar Oct 11 '18 20:10 hillc5

onChange is called only when the input value changes. In your repro, the input value changes when you press Down, but not when you press Enter.

It will be called with method === "enter" if you hover a suggestion with a mouse (this doesn't change the input value), and then press Enter.

You might want to use onSuggestionSelected.

moroshko avatar Oct 11 '18 21:10 moroshko