SearchPageForm.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import SearchForm from '../SearchForm';
  4. // Search.SearchForm
  5. export default class SearchPageForm extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. keyword: this.props.keyword,
  10. searchedKeyword: this.props.keyword,
  11. };
  12. this.search = this.search.bind(this);
  13. this.onSubmit = this.onSubmit.bind(this);
  14. this.onInputChange = this.onInputChange.bind(this);
  15. }
  16. search(keyword) {
  17. if (this.state.searchedKeyword != keyword) {
  18. this.props.onSearchFormChanged({keyword: keyword});
  19. this.setState({searchedKeyword: keyword});
  20. }
  21. }
  22. onSubmit(event) { // submit with button
  23. event.preventDefault(); // prevent refreshing page
  24. this.search(this.state.keyword);
  25. }
  26. onInputChange(input) {
  27. this.setState({keyword: input});
  28. }
  29. render() {
  30. return (
  31. <form ref='form'
  32. className="form form-group input-group"
  33. onSubmit={this.onSubmit}
  34. >
  35. <SearchForm
  36. crowi={this.props.crowi}
  37. onSubmit={this.search}
  38. keyword={this.state.searchedKeyword}
  39. onInputChange={this.onInputChange}
  40. />
  41. <span className="input-group-btn">
  42. <button type="submit" className="btn btn-default">
  43. <i className="search-top-icon icon-magnifier"></i>
  44. </button>
  45. </span>
  46. </form>
  47. );
  48. }
  49. }
  50. SearchPageForm.propTypes = {
  51. crowi: PropTypes.object.isRequired,
  52. keyword: PropTypes.string,
  53. onSearchFormChanged: PropTypes.func.isRequired,
  54. };
  55. SearchPageForm.defaultProps = {
  56. };