I'm trying to track an onChange event on a SearchBox component from the library Searchkit . I want to make some kind of autocomplete-popup, below the input field.
I'm having a Searchbar component and a SearchbarPopup component. When I type something inside the Searchbox input I want the to show or hide when input is empty. But for now I'm fine with getting a response from the console.log.
export class Searchbar extends Component {
constructor(props){
super(props)
this.onChange = this.onChange.bind(this)
}
onChange(){
console.log('input has changed!')
}
render() {
return (
<SearchkitProvider searchkit={searchkit}>
<Layout>
<div className="search">
<div className="search_query">
<SearchBox
autofocus={true}
searchOnChange={true}
onChange={this.onChange}
prefixQueryFields={[
"Author",
"Title"
]}
/>
</div>
</div>
</Layout>
</SearchkitProvider>
);
}
}
Rendered HTML
<div id="cb_Zoekbalk">
<div class="sk-layout">
<div class="search">
<div class="search_query">
<div class="sk-search-box">
<form>
<div class="sk-search-box__icon"></div>
<input type="text" data-qa="query" class="sk-search-box__text" placeholder="Waar ben je naar op zoek?" value="">
<input type="submit" value="search" class="sk-search-box__action" data-qa="submit">
<div data-qa="loader" class="sk-search-box__loader sk-spinning-loader is-hidden"></div>
</form>
</div>
</div>
</div>
</div>
</div>
In my project, I'm also needed to set a listener on SearchBox query change. Here is what place I've found where you can get a response:
searchkit.setQueryProcessor((plainQueryObject) => {
console.log('input has changed!')
return plainQueryObject
})
Link to a documentation for SearchkitManager
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.