Merge pull request #229 from tomalrussell/feature/clear_pc_search_results

Fix for issue #198 enable postcode search to shut
This commit is contained in:
Tom Russell 2019-03-24 21:40:47 +00:00 committed by GitHub
commit d86ad2cedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,13 +16,41 @@ class SearchBox extends Component {
} }
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.search = this.search.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 // Update search term
handleChange(e) { handleChange(e) {
this.setState({ this.setState({
q: e.target.value 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 // Query search endpoint
@ -87,7 +115,7 @@ class SearchBox extends Component {
</ul> </ul>
: null; : null;
return ( return (
<div className={`search-box ${this.props.is_building? "building" : ""}`}> <div className={`search-box ${this.props.is_building? "building" : ""}`} onKeyDown={this.handleKeyPress}>
<form action="/search" method="GET" onSubmit={this.search} <form action="/search" method="GET" onSubmit={this.search}
className="form-inline"> className="form-inline">
<input <input