SearchPageForm.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import FormGroup from 'react-bootstrap/es/FormGroup';
  4. import Button from 'react-bootstrap/es/Button';
  5. import InputGroup from 'react-bootstrap/es/InputGroup';
  6. import SearchForm from '../SearchForm';
  7. // Search.SearchForm
  8. export default class SearchPageForm extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. keyword: this.props.keyword,
  13. searchedKeyword: this.props.keyword,
  14. };
  15. this.search = this.search.bind(this);
  16. this.onInputChange = this.onInputChange.bind(this);
  17. }
  18. search() {
  19. const keyword = this.state.keyword;
  20. this.props.onSearchFormChanged({keyword: keyword});
  21. this.setState({searchedKeyword: keyword});
  22. }
  23. onInputChange(input) { // for only submitting with button
  24. this.setState({keyword: input});
  25. }
  26. render() {
  27. return <FormGroup>
  28. <InputGroup>
  29. <SearchForm t={this.props.t}
  30. crowi={this.props.crowi}
  31. onSubmit={this.search}
  32. keyword={this.state.searchedKeyword}
  33. onInputChange={this.onInputChange}
  34. />
  35. <InputGroup.Button className="">
  36. <Button onClick={this.search}>
  37. <i className="icon-magnifier"></i>
  38. </Button >
  39. </InputGroup.Button>
  40. </InputGroup>
  41. </FormGroup>;
  42. }
  43. }
  44. SearchPageForm.propTypes = {
  45. t: PropTypes.func.isRequired, // i18next
  46. crowi: PropTypes.object.isRequired,
  47. keyword: PropTypes.string,
  48. onSearchFormChanged: PropTypes.func.isRequired,
  49. };
  50. SearchPageForm.defaultProps = {
  51. };