Jelajahi Sumber

refs #237
- 検索文字列の初期値を入力
- リセットボタンを押すと初期値を入力

Ryu Sato 8 tahun lalu
induk
melakukan
8253092622

+ 5 - 3
resource/js/components/NewPageNameInputter.js

@@ -60,9 +60,12 @@ export default class NewPageNameInputter extends React.Component {
     this.setState({input: text});
   }
 
+  /**
+   * Initialize keyword
+   */
   restoreForm() {
     this._searchtypeahead._typeahead.getInstance().clear();
-    this._searchtypeahead._typeahead.getInstance().input = 'hoge';
+    this._searchtypeahead._typeahead.getInstance()._updateText(this.props.parentPageName);
   }
 
   renderMenuItemChildren(option, props, index) {
@@ -83,7 +86,7 @@ export default class NewPageNameInputter extends React.Component {
 
     return (
       <SearchTypeahead
-        ref={searchTypeahead => this._searchtypeahead = searchTypeahead}
+        ref={(searchTypeahead) => this._searchtypeahead = searchTypeahead}
         crowi={this.crowi}
         onSearchSuccess={this.onSearchSuccess}
         onSearchError={this.onSearchError}
@@ -99,5 +102,4 @@ NewPageNameInputter.propTypes = {
   parentPageName: PropTypes.string.isRequired,
 };
 NewPageNameInputter.defaultProps = {
-  parentPageName: "",
 };

+ 5 - 4
resource/js/components/SearchTypeahead.js

@@ -120,7 +120,6 @@ export default class SearchTypeahead extends React.Component {
         ? 'Error on searching.'
         : 'No matches found on title...';
     const restoreFormButton = this.getRestoreFormButton();
-    const keyword = "hoge";
 
     return (
       <form
@@ -128,12 +127,12 @@ export default class SearchTypeahead extends React.Component {
         className=""
         >
       <AsyncTypeahead
-        ref={typeahead => this._typeahead = typeahead}
+        ref={(typeahead) => this._typeahead = typeahead}
         inputProps={{name: "q", autoComplete: "off"}}
         isLoading={this.state.isLoading}
         labelKey="path"
         minLength={2}
-        options={this.state.pages}
+        options={this.state.pages} // 検索結果
         placeholder="Input page name"
         emptyLabel={this.emptyLabel ? this.emptyLabel : emptyLabel}
         align='left'
@@ -142,9 +141,11 @@ export default class SearchTypeahead extends React.Component {
         onInputChange={this.onInputChange}
         renderMenuItemChildren={this.renderMenuItemChildren}
         caseSensitive={false}
+        defaultSelected={[{path: this.props.keywordOnInit}]}
       />
       {restoreFormButton}
-      <span>keyword: {this.state.keyword}</span>
+      {/* [TODO] デバッグ用の表示。実装が完了したら削除する。 */}
+      <span>keyword: {this.state.keyword}, keywordOnInit: {this.props.keywordOnInit}</span>
       </form>
     );
   }

+ 1 - 0
resource/js/legacy/crowi.js

@@ -241,6 +241,7 @@ $(function() {
       ;
     $('#page-name-inputter .form-control').focus(); // focus() を実行しないと placeholder が表示されない。
     $('#create-page-today .form-control.page-today-input2').css({width: newWidth}).focus();
+
   });
 
   $('#create-page-today').submit(function(e) {