yes
inputProps.onChange is not executing c, and wait for suggestions to appearObserved behaviour: Suggestions stay open
Expected behaviour: Suggestions should be closed
Please describe your use case from user journey point of view, e.g.:
In my application, when user highlights suggestions (using the mouse or keyboard), I'd like to display additional information about the highlighted suggestion alongside the Autosuggest.
If you have ideas how to extend the Autosuggest API to support your new feature, please share!
If you know any examples online that already implement such functionality, please share a link.
You can pass the onKeyPress event handler to the input props.
const inputProps = {
placeholder: 'Search for something...',
value,
onChange: this.onChange,
onKeyPress: this.onKeyPress
}
and this is how you will use the handler function to check for enter key press
onKeyPress = (e) => {
if(e.key === 'Enter'){
//do something
}
}
Make sure to pass the inputProps to the <Autosuggest inputProps={inputProps} ...
You can further customise the input component using the renderInputComponent method. I have used React semantic UI input as the input component.
const renderInputComponent = inputProps => (
<div>
<Input style={{width: '350px'}} icon='search' {...inputProps} />
</div>
);
Bumping this thread since although evt.key does work, evt.keyCode always returns 0. So thanks for the tip, but there is still an issue with events.
@amalajith Do you know if it is possible to get the all suggestion and not the suggestionValue ?
Because here
onKeyPress = (e) => {
if(e.key === 'Enter'){
//do something
}
}
e will contain the target that will contain the value, but what if i my value are {id: ..., name: ....} and i need to get the id and not the name. Is there a way to get like in the onSuggestionSelected method ?
Thanks
Most helpful comment
You can pass the onKeyPress event handler to the input props.
and this is how you will use the handler function to check for enter key press
Make sure to pass the inputProps to the
<Autosuggest inputProps={inputProps} ...You can further customise the input component using the renderInputComponent method. I have used React semantic UI input as the input component.