我正在尝试跟踪库Searchkit中SearchBox组件上的 onChange 事件。我想在输入字段下方制作某种自动完成弹出窗口。
我有一个 Searchbar 组件和一个 SearchbarPopup 组件。当我在搜索框输入中输入内容时,我希望在输入为空时显示或隐藏。但现在我可以从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>
);
}
}
呈现的 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>