| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import React from 'react';
- // Search.SearchForm
- export default class SearchForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- keyword: this.props.keyword,
- searchedKeyword: this.props.keyword,
- };
- this.handleSubmit = this.handleSubmit.bind(this);
- this.handleChange = this.handleChange.bind(this);
- }
- componentDidMount() {
- }
- componentWillUnmount() {
- }
- search() {
- if (this.state.searchedKeyword != this.state.keyword) {
- this.props.onSearchFormChanged({keyword: this.state.keyword});
- this.setState({searchedKeyword: this.state.keyword});
- }
- }
- handleSubmit(event) {
- event.preventDefault();
- this.search({keyword: this.state.keyword});
- }
- handleChange(event) {
- const keyword = event.target.value;
- this.setState({keyword});
- }
- render() {
- return (
- <form className="form" onSubmit={this.handleSubmit}>
- <input
- type="text"
- name="q"
- value={this.state.keyword}
- onChange={this.handleChange}
- className="form-control"
- />
- </form>
- );
- }
- }
- SearchForm.propTypes = {
- onSearchFormChanged: React.PropTypes.func.isRequired,
- };
- SearchForm.defaultProps = {
- };
|