@@ -67,6 +67,7 @@ class SearchBar extends Component {
6767
6868 handleSuggestionsUpdate ( requestNo , data ) {
6969 if ( requestNo === this . state . maxRequestNo ) {
70+ console . log ( 'SUGGESTIONS' , data )
7071 this . setState ( { loading : false , suggestions : data , selectedSuggestionIdx : null } )
7172 }
7273 }
@@ -102,6 +103,7 @@ class SearchBar extends Component {
102103 this . refs . searchValue . value = null
103104 this . setState ( { searchValue : this . refs . searchValue . value } )
104105 this . setState ( { searchState : 'empty' } )
106+ this . setState ( { suggestions : false } )
105107 this . props . onClearSearch ( )
106108 }
107109
@@ -191,11 +193,11 @@ class SearchBar extends Component {
191193
192194 const results = this . state . loading === true
193195 ? < div className = "loading-suggestions" > < Loader /> </ div >
194- : < SearchSuggestions recentSearch = { recentList } searchTerm = { this . state . searchValue } popularSearch = { popularList } onSuggestionSelect = { this . handleSuggestionSelect } />
196+ : < SearchSuggestions hideSuggestionsWhenEmpty = { this . props . hideSuggestionsWhenEmpty } recentSearch = { recentList } searchTerm = { this . state . searchValue } popularSearch = { popularList } showPopularSearchHeader = { this . props . showPopularSearchHeader } onSuggestionSelect = { this . handleSuggestionSelect } />
195197 return (
196198 < div className = { sbClasses } >
197- < input className = "search-bar__text" onFocus = { this . onFocus } onChange = { this . onChange } onKeyUp = { this . onKeyUp } ref = "searchValue" value = { this . state . searchValue } />
198199 < span className = "search-typeahead-text" > { typeaheadText } </ span >
200+ < input className = "search-bar__text" onFocus = { this . onFocus } onChange = { this . onChange } onKeyUp = { this . onKeyUp } ref = "searchValue" value = { this . state . searchValue } />
199201 < img className = "search-bar__clear" src = { require ( './x-mark.svg' ) } onClick = { this . clearSearch } />
200202 < div className = "search-icon-wrap" onClick = { this . search } >
201203 < img className = "search-bar__icon" src = { require ( './icon-search.png' ) } />
@@ -209,19 +211,22 @@ class SearchBar extends Component {
209211 }
210212}
211213
212-
213214SearchBar . propTypes = {
215+ hideSuggestionsWhenEmpty : PropTypes . func . bool ,
214216 onSearch : PropTypes . func . isRequired ,
215217 onClearSearch : PropTypes . func ,
216218 onTermChange : PropTypes . func . isRequired ,
217219 recentTerms : PropTypes . array ,
218- searchTermKey : PropTypes . string
220+ searchTermKey : PropTypes . string ,
221+ showPopularSearchHeader : PropTypes . bool
219222}
220223
221224SearchBar . defaultProps = {
225+ hideSuggestionsWhenEmpty : false ,
222226 recentTerms : [ ] ,
223227 searchTermKey : 'q' ,
224- onClearSearch : ( ) => { }
228+ onClearSearch : ( ) => { } ,
229+ showPopularSearchHeader : true
225230}
226231
227232export default SearchBar
0 commit comments