Skip to content

Commit d53cb37

Browse files
author
Emmanouil Konstantinidis
committed
Clear Search if toggle off
1 parent c2699fa commit d53cb37

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/js/__tests__/components/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ describe('Test for Footer', function () {
6464
});
6565

6666
expect(Actions.updateSearchTerm).toHaveBeenCalledWith('hello');
67+
68+
instance.componentWillReceiveProps({showSearch: false});
69+
expect(Actions.updateSearchTerm).toHaveBeenCalledWith('');
6770
});
6871

6972
it('Should only render clear button if search term is not empty', function () {

src/js/components/search.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ var Search = React.createClass({
1414
};
1515
},
1616

17+
componentWillReceiveProps: function(nextProps) {
18+
if (nextProps.showSearch === false) {
19+
this.setState({
20+
searchTerm: ''
21+
});
22+
Actions.updateSearchTerm('');
23+
}
24+
},
25+
1726
updateSearchTerm: function (event) {
1827
this.setState({
1928
searchTerm: event.target.value

0 commit comments

Comments
 (0)