Hi , can we add onEnter event to the input that triggered even when suggestion aren't selected?
for example when the input are empty , i would like to press enter, then when value are empty i want to trigger my custom event maybe for resetting content for my API
Thank you
Hey @zeroseed,
I'm not the maintainer but I just wanted to let you know you can already do this through inputProps. You can just add an onKeyDown prop to your inputProps and it will be called.
You can then match you use-case easily:
// ... input props
onKeyDown: (event) => {
if (event.keyCode === 13 /* enter */ && !value /* or whatever variable you store the input content in */) {
// Handle your onEnter logic
}
},
// ... more input props
As you can see here and there, react-autosuggest makes sure it does not ignore your own handlers.
The only restriction is your handler will be called after the regular react-autosuggest logic. I'm not sure this alone warrants the addition of a specific prop for this use case.
Hope this helps 馃槄
Most helpful comment
Hey @zeroseed,
I'm not the maintainer but I just wanted to let you know you can already do this through
inputProps. You can just add anonKeyDownprop to yourinputPropsand it will be called.You can then match you use-case easily:
As you can see here and there,
react-autosuggestmakes sure it does not ignore your own handlers.The only restriction is your handler will be called after the regular
react-autosuggestlogic. I'm not sure this alone warrants the addition of a specific prop for this use case.Hope this helps 馃槄