SearchPageForm.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 });
  21. this.setState({ searchedKeyword: keyword });
  22. }
  23. onInputChange(input) { // for only submitting with button
  24. this.setState({ keyword: input });
  25. }
  26. render() {
  27. return (
  28. <FormGroup>
  29. <InputGroup>
  30. <SearchForm
  31. t={this.props.t}
  32. crowi={this.props.crowi}
  33. onSubmit={this.search}
  34. keyword={this.state.searchedKeyword}
  35. onInputChange={this.onInputChange}
  36. />
  37. <InputGroup.Button className="">
  38. <Button onClick={this.search}>
  39. <i className="icon-magnifier"></i>
  40. </Button>
  41. </InputGroup.Button>
  42. </InputGroup>
  43. </FormGroup>
  44. );
  45. }
  46. }
  47. SearchPageForm.propTypes = {
  48. t: PropTypes.func.isRequired, // i18next
  49. crowi: PropTypes.object.isRequired,
  50. keyword: PropTypes.string,
  51. onSearchFormChanged: PropTypes.func.isRequired,
  52. };
  53. SearchPageForm.defaultProps = {
  54. };