Last active
October 5, 2017 18:52
-
-
Save JavierPons/1c80e52a8b1cb9c115a76b80b03dd7e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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