Skip to content

Commit 8aab14b

Browse files
author
Parth Shah
committed
adding optional onClearSearch prop
1 parent 2e21afc commit 8aab14b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

components/SearchBar/SearchBar.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class SearchBar extends Component {
2727
this.handleSuggestionsUpdate = this.handleSuggestionsUpdate.bind(this)
2828
}
2929

30-
getQueryStringValue (key) {
30+
getQueryStringValue (key) {
3131
return unescape(window.location.href.replace(new RegExp('^(?:.*[&\\?]' + escape(key).replace(/[\.\+\*]/g, '\\$&') + '(?:\\=([^&]*))?)?.*$', 'i'), '$1'))
32-
}
32+
}
3333

3434
componentDidMount() {
3535
window.addEventListener('click', this.handleOutsideClick)
@@ -102,6 +102,7 @@ class SearchBar extends Component {
102102
this.refs.searchValue.value = null
103103
this.setState({ searchValue: this.refs.searchValue.value })
104104
this.setState({ searchState: 'empty' })
105+
this.props.onClearSearch()
105106
}
106107

107108
onKeyUp(evt) {
@@ -211,14 +212,16 @@ class SearchBar extends Component {
211212

212213
SearchBar.propTypes = {
213214
onSearch : PropTypes.func.isRequired,
215+
onClearSearch : PropTypes.func,
214216
onTermChange : PropTypes.func.isRequired,
215217
recentTerms : PropTypes.array,
216218
searchTermKey: PropTypes.string
217219
}
218220

219221
SearchBar.defaultProps = {
220222
recentTerms : [],
221-
searchTermKey : 'q'
223+
searchTermKey : 'q',
224+
onClearSearch : () => {}
222225
}
223226

224227
export default SearchBar

0 commit comments

Comments
 (0)