pstanoev / simple-svelte-autocomplete

Simple Autocomplete / typeahead component for Svelte
http://simple-svelte-autocomplete.surge.sh/
MIT License
468 stars 79 forks source link

Item selection not working on enter #142

Closed atomcat1978 closed 2 years ago

atomcat1978 commented 2 years ago

Version: 2.3.2

It seems like there is an error when one uses enter to select an item in the dropdown list.

The problem is the following: onKeyDown is called prior to onKeyPress, however, onKeyDown doe close the dropdown. Than when the execution comes to onKeyPress, the call to onEnter is not executed due to the opened flag, which was set to false by onKeyDown :

  function onKeyPress(e) {
    if (debug) {
      console.log("onKeyPress")
    }
    if (e.key === "Enter" && opened) { // << == HERE
      e.preventDefault()
      onEnter()
    }
  }

Fix: remove && opened.

Related PR: https://github.com/pstanoev/simple-svelte-autocomplete/pull/143

pstanoev commented 2 years ago

Fix published with version 2.3.3.

atomcat1978 commented 2 years ago

Thxs.