downshift-js / downshift

🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.

Home Page:http://downshift-js.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onSelect is called with undefined when clicked on escape

venkateshwarreddyr opened this issue · comments

  • downshift version: 8.1.0
  • node version:
  • npm (or yarn) version:

Relevant code or config

What you did:

What happened:

Reproduction repository:

Problem description:
onSelect is called with undefined when clicked on escape with empty values

Reproduction Steps

  1. Sandbox:
    https://codesandbox.io/s/downshift-how-to-reset-inputvalue-after-running-onselect-forked-fqmqch
  2. click on input field
  3. click on escape
  4. (issue) onSelect is called (this should not happen)
image

Expected:
When clicked on Escape button it should not call onSelect function.

Suggested solution:

@silviuaavram can you pls check this?

This check has been around for quite some time isItemSelected = newStateToSet.hasOwnProperty('selectedItem') and I don't think I'm going to do any more changes in Downshift, since we are using useCombobox now.

So, add a check for undefined in your handler, if you don't want to do anything in that case. I don't think the behaviour is totally wrong, since the selectedItem does change on Escape. If there was a selectedItem before and you hit Escape, now it should be undefined, and onSelect helps you know that.

I would also switch from Downshift to useCombobox, too. Thanks!