diff --git a/app/src/frontend/search-box.js b/app/src/frontend/search-box.js index 4420d89b..e48815de 100644 --- a/app/src/frontend/search-box.js +++ b/app/src/frontend/search-box.js @@ -16,13 +16,41 @@ class SearchBox extends Component { } this.handleChange = this.handleChange.bind(this); this.search = this.search.bind(this); + this.handleKeyPress = this.handleKeyPress.bind(this); + this.clearResults = this.clearResults.bind(this); + this.clearQuery = this.clearQuery.bind(this); } // Update search term handleChange(e) { this.setState({ q: e.target.value - }) + }); + // If the ‘clear’ icon has been clicked, clear results list as well + if(e.target.value === "") { + this.clearResults(); + } + } + + // Clear search results on ESC + handleKeyPress(e){ + if(e.keyCode === 27) { + //ESC is pressed + this.clearQuery(); + this.clearResults(); + } + } + + clearResults(){ + this.setState({ + results: [] + }); + } + + clearQuery(){ + this.setState({ + q: "" + }); } // Query search endpoint @@ -87,7 +115,7 @@ class SearchBox extends Component { : null; return ( -