Parcourir la source

enable to submit with a search button

yusuketk il y a 7 ans
Parent
commit
4d3d82d16e

+ 2 - 1
src/client/js/components/SearchForm.js

@@ -68,10 +68,10 @@ export default class SearchForm extends React.Component {
 
 
     return (
     return (
       <SearchTypeahead
       <SearchTypeahead
-        ref = 'searchTypeahead'
         crowi={this.props.crowi}
         crowi={this.props.crowi}
         onChange={this.onChange}
         onChange={this.onChange}
         onSubmit={this.props.onSubmit}
         onSubmit={this.props.onSubmit}
+        onInputChange={this.props.onInputChange}
         onSearchError={this.onSearchError}
         onSearchError={this.onSearchError}
         emptyLabel={emptyLabel}
         emptyLabel={emptyLabel}
         placeholder="Search ..."
         placeholder="Search ..."
@@ -86,6 +86,7 @@ SearchForm.propTypes = {
   crowi: PropTypes.object.isRequired,
   crowi: PropTypes.object.isRequired,
   keyword: PropTypes.string,
   keyword: PropTypes.string,
   onSubmit: PropTypes.func.isRequired,
   onSubmit: PropTypes.func.isRequired,
+  onInputChange: PropTypes.func,
 };
 };
 
 
 SearchForm.defaultProps = {
 SearchForm.defaultProps = {

+ 13 - 1
src/client/js/components/SearchPage/SearchPageForm.js

@@ -9,10 +9,13 @@ export default class SearchPageForm extends React.Component {
     super(props);
     super(props);
 
 
     this.state = {
     this.state = {
+      keyword: this.props.keyword,
       searchedKeyword: this.props.keyword,
       searchedKeyword: this.props.keyword,
     };
     };
 
 
     this.search = this.search.bind(this);
     this.search = this.search.bind(this);
+    this.onSubmit = this.onSubmit.bind(this);
+    this.onInputChange = this.onInputChange.bind(this);
   }
   }
 
 
   search(keyword) {
   search(keyword) {
@@ -22,6 +25,15 @@ export default class SearchPageForm extends React.Component {
     }
     }
   }
   }
 
 
+  onSubmit(event) { // submit with button
+    event.preventDefault(); // prevent refreshing page
+    this.search(this.state.keyword);
+  }
+
+  onInputChange(input) {
+    this.setState({keyword: input});
+  }
+
   render() {
   render() {
     return (
     return (
       <form ref='form'
       <form ref='form'
@@ -29,10 +41,10 @@ export default class SearchPageForm extends React.Component {
         onSubmit={this.onSubmit}
         onSubmit={this.onSubmit}
       >
       >
         <SearchForm
         <SearchForm
-          ref='searchForm'
           crowi={this.props.crowi}
           crowi={this.props.crowi}
           onSubmit={this.search}
           onSubmit={this.search}
           keyword={this.state.searchedKeyword}
           keyword={this.state.searchedKeyword}
+          onInputChange={this.onInputChange}
         />
         />
         <span className="input-group-btn">
         <span className="input-group-btn">
           <button type="submit" className="btn btn-default">
           <button type="submit" className="btn btn-default">

+ 2 - 0
src/client/js/components/SearchTypeahead.js

@@ -92,6 +92,7 @@ export default class SearchTypeahead extends React.Component {
 
 
   onInputChange(text) {
   onInputChange(text) {
     this.setState({input: text});
     this.setState({input: text});
+    this.props.onInputChange(text);
     if (text === '') {
     if (text === '') {
       this.setState({pages: []});
       this.setState({pages: []});
     }
     }
@@ -186,6 +187,7 @@ SearchTypeahead.propTypes = {
   onSearchError:   PropTypes.func,
   onSearchError:   PropTypes.func,
   onChange:        PropTypes.func,
   onChange:        PropTypes.func,
   onSubmit:        PropTypes.func,
   onSubmit:        PropTypes.func,
+  onInputChange:   PropTypes.func,
   emptyLabel:      PropTypes.string,
   emptyLabel:      PropTypes.string,
   placeholder:     PropTypes.string,
   placeholder:     PropTypes.string,
   keywordOnInit:   PropTypes.string,
   keywordOnInit:   PropTypes.string,