File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments