Update searchbar to query with empty term

This commit is contained in:
Sundeep Chand 2020-07-28 12:48:52 +05:30
parent e299bf2a39
commit 1091a4e4af

View file

@ -23,25 +23,19 @@ class Searchbar extends React.Component {
}); });
} }
handleSearchEnter = (e) => { // handleSearchEnter = (e) => {
if (e.key === 'Enter') { // if (e.key === 'Enter') {
this.searchChange(); // this.searchChange();
} // }
} // }
searchChange = () => { searchChange = () => {
if (this.state.searchValue.trim().length === 0) return;
this.props.setSearchTerm(this.state.searchValue.trim()); this.props.setSearchTerm(this.state.searchValue.trim());
}; };
handleSearchChange = (e) => { handleSearchChange = (e) => {
if (e.target.value === '') {
// Manually reset the searchValue if the search field becomes empty.
this.handleResetSearch();
return;
}
this.setState({ searchValue: e.target.value }, () => { this.setState({ searchValue: e.target.value }, () => {
this.throttledSearchChange(this.state.searchValue); this.throttledSearchChange(this.state.searchValue.trim());
}); });
} }
@ -58,7 +52,7 @@ class Searchbar extends React.Component {
value={searchValue} value={searchValue}
placeholder={this.props.searchLabel} placeholder={this.props.searchLabel}
onChange={this.handleSearchChange} onChange={this.handleSearchChange}
onKeyUp={this.handleSearchEnter} // onKeyUp={this.handleSearchEnter}
/> />
<button <button
className="searchbar__clear-button" className="searchbar__clear-button"