Skip to content

Instantly share code, notes, and snippets.

@JavierPons
Last active October 5, 2017 18:52
Show Gist options
  • Save JavierPons/1c80e52a8b1cb9c115a76b80b03dd7e7 to your computer and use it in GitHub Desktop.
Save JavierPons/1c80e52a8b1cb9c115a76b80b03dd7e7 to your computer and use it in GitHub Desktop.
import React from 'react';
import './SearchBar.css';
class SearchBar extends React.Component {
constructor(props) {
super(props);
this.state = {
term: ''
};
this.handleTermChange = this.handleTermChange.bind(this);
this.search = this.search.bind(this);
this.pressEnter = this.pressEnter.bind(this);
}
handleTermChange(event) {
this.setState({term: event.target.value});
}
search() {
this.props.onSearch(this.state.term);
console.log('this is done')
}
pressEnter = (event) => {
if (event.key === 'Enter') {
this.search();
};
}
render(){
return(
<div className="SearchBar" type="submit">
<input placeholder="Enter A Song, Album, or Artist" onKeyPress={this.pressEnter} onChange={this.handleTermChange} />
<a onClick={this.search}>SEARCH</a>
</div>
);
}
}
export default SearchBar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment