Reputation: 331
What I’m looking for is to run the Search function when the device’s enter key is pressed but I can’t do it. If with onIonChange I can filter the words
What event is necessary to use to detect the enter on the device? onIonInput does not works to detects enter key
const Search = () =>{
//do something
}
const Words = (value:any) =>{
//do something
}
return(
<>
<IonSearchbar debounce={500} type="text" onIonChange={e => {Words(e.detail.value!)}} onIonInput={ Search} ></IonSearchbar>
</>
)
};
Upvotes: 1
Views: 512
Reputation: 21
You could use onKeyPress
with event.key
to listen for the enter to key.
const keypress = (event) => {
if(event.key === 'Enter') {
// Run search function
}
}
return(
<>
<IonSearchbar onKeyPress={keypress}></IonSearchbar>
</>
)};
Upvotes: 1