moroshko / react-autosuggest

WAI-ARIA compliant React autosuggest component
http://react-autosuggest.js.org
MIT License
5.97k stars 586 forks source link

Don't call `onSuggestionSelected` when list is hidden and enter key is pressed #696

Open OliverJAsh opened 4 years ago

OliverJAsh commented 4 years ago

https://codepen.io/OliverJAsh/pen/ZEEOoZq?editors=0011

Steps to reproduce:

  1. Focus on the input field
  2. Type c
  3. Escape/dismiss suggestions
  4. Now the suggestions list is hidden, press enter

Observed behaviour:

This doesn't seem like intuitive behaviour—how can something that is hidden be selected?

Expected behaviour: no suggestion is selected at step 4

Related: https://github.com/moroshko/react-autosuggest/issues/483

IIUC, we can workaround this by clearing the suggestions when a selection is made (via onSuggestionsClearRequested). However, this is not always desirable—we may want to keep the suggestions in state so they can be immediately shown again when the input regains focus.

dsaw commented 4 years ago

Interesting. This issue doesn't seem to come up when using an async function to fetch results, probably because the list is fetched every time input is changed & no value corresponds to an empty suggestion list.