onSelect is called with undefined when clicked on escape
venkateshwarreddyr opened this issue · comments
downshift
version: 8.1.0node
version:npm
(oryarn
) 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
- Sandbox:
https://codesandbox.io/s/downshift-how-to-reset-inputvalue-after-running-onselect-forked-fqmqch - click on input field
- click on escape
- (issue) onSelect is called (this should not happen)
![image](https://private-user-images.githubusercontent.com/51945078/267715334-66ff3f52-839f-4d6a-beed-91d97a51d930.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI0OTUyNzUsIm5iZiI6MTcxMjQ5NDk3NSwicGF0aCI6Ii81MTk0NTA3OC8yNjc3MTUzMzQtNjZmZjNmNTItODM5Zi00ZDZhLWJlZWQtOTFkOTdhNTFkOTMwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDA3VDEzMDI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRiNDJlOTAwZDAxNTNiNzJkMjBmOTcyNTk0ZDE4YWNkYWJhYWE0MjNjN2IyY2UwN2M5YWVkNmNiMTM0MDRmZWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.LxwNEuPusuQIZcKLaE9dabvkHgHQc_NX3EfiOmALXhw)
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!