Skip to content

Commit 988fae3

Browse files
author
vikasrohit
committed
AS#113534192025964, Trim search value in SearchBar
AS#113534202832111, SearchBar - Do not search with empty search term -- Done
1 parent 5de4a19 commit 988fae3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

components/SearchBar/SearchBar.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,27 @@ class SearchBar extends Component {
6464

6565
onChange() {
6666
const oldTerm = this.state.searchValue
67+
const newTerm = this.refs.searchValue.value ? this.refs.searchValue.value.trim() : ''
6768
this.setState(
6869
function(prevState) {
6970
const rc = prevState.requestNo ? prevState.requestNo + 1 : 1
7071
return {
7172
searchValue: this.refs.searchValue.value,
7273
requestNo: rc,
7374
maxRequestNo: rc,
74-
loading: true,
75+
loading: newTerm.length > 0 ? true : false,
7576
searchState: 'focused'
7677
}
7778
},
7879
function() {
79-
this.props.onTermChange.apply(null, [
80-
oldTerm,
81-
this.state.searchValue,
82-
this.state.requestNo,
83-
this.handleSuggestionsUpdate
84-
])
80+
if (newTerm.length > 0) {
81+
this.props.onTermChange.apply(null, [
82+
oldTerm,
83+
newTerm,
84+
this.state.requestNo,
85+
this.handleSuggestionsUpdate
86+
])
87+
}
8588
}
8689
)
8790
}
@@ -143,7 +146,10 @@ class SearchBar extends Component {
143146
}
144147

145148
search() {
146-
this.props.onSearch.apply(this, [this.state.searchValue])
149+
const searchTerm = this.state.searchValue ? this.state.searchValue.trim() : ''
150+
if(searchTerm.length > 0) {
151+
this.props.onSearch.apply(this, [searchTerm])
152+
}
147153
}
148154

149155
render() {

0 commit comments

Comments
 (0)