zamis 5 سال پیش
والد
کامیت
e0b07fd04b
1فایلهای تغییر یافته به همراه71 افزوده شده و 43 حذف شده
  1. 71 43
      src/client/js/components/SearchForm.jsx

+ 71 - 43
src/client/js/components/SearchForm.jsx

@@ -13,10 +13,13 @@ class SearchForm extends React.Component {
 
 
     this.state = {
     this.state = {
       searchError: null,
       searchError: null,
+      isCloseHelp: null,
     };
     };
 
 
     this.onSearchError = this.onSearchError.bind(this);
     this.onSearchError = this.onSearchError.bind(this);
     this.onChange = this.onChange.bind(this);
     this.onChange = this.onChange.bind(this);
+    this.onBlur = this.onBlur.bind(this);
+    this.onFocus = this.onFocus.bind(this);
   }
   }
 
 
   componentDidMount() {
   componentDidMount() {
@@ -40,12 +43,28 @@ class SearchForm extends React.Component {
     }
     }
   }
   }
 
 
+  onBlur() {
+    this.setState({
+      isCloseHelp: true,
+    });
+
+    this.getHelpElement();
+  }
+
+  onFocus() {
+    this.setState({
+      isCloseHelp: false,
+    });
+  }
+
   getHelpElement() {
   getHelpElement() {
     const { t, appContainer } = this.props;
     const { t, appContainer } = this.props;
 
 
     const config = appContainer.getConfig();
     const config = appContainer.getConfig();
     const isReachable = config.isSearchServiceReachable;
     const isReachable = config.isSearchServiceReachable;
 
 
+    console.log(this.state.isCloseHelp);
+
     if (!isReachable) {
     if (!isReachable) {
       return (
       return (
         <>
         <>
@@ -55,49 +74,55 @@ class SearchForm extends React.Component {
       );
       );
     }
     }
 
 
-    return (
-      <table className="table grw-search-table search-help m-0">
-        <caption className="text-left text-primary p-2">
-          <h5 className="h6"><i className="icon-magnifier pr-2 mb-2" />{ t('search_help.title') }</h5>
-        </caption>
-        <tbody>
-          <tr>
-            <th className="py-2">
-              <code>word1</code> <code>word2</code><br></br>
-              <small>({ t('search_help.and.syntax help') })</small>
-            </th>
-            <td><h6 className="m-0">{ t('search_help.and.desc', { word1: 'word1', word2: 'word2' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2">
-              <code>&quot;This is GROWI&quot;</code><br></br>
-              <small>({ t('search_help.phrase.syntax help') })</small>
-            </th>
-            <td><h6 className="m-0">{ t('search_help.phrase.desc', { phrase: 'This is GROWI' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2"><code>-keyword</code></th>
-            <td><h6 className="m-0">{ t('search_help.exclude.desc', { word: 'keyword' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2"><code>prefix:/user/</code></th>
-            <td><h6 className="m-0">{ t('search_help.prefix.desc', { path: '/user/' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2"><code>-prefix:/user/</code></th>
-            <td><h6 className="m-0">{ t('search_help.exclude_prefix.desc', { path: '/user/' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2"><code>tag:wiki</code></th>
-            <td><h6 className="m-0">{ t('search_help.tag.desc', { tag: 'wiki' }) }</h6></td>
-          </tr>
-          <tr>
-            <th className="py-2"><code>-tag:wiki</code></th>
-            <td><h6 className="m-0">{ t('search_help.exclude_tag.desc', { tag: 'wiki' }) }</h6></td>
-          </tr>
-        </tbody>
-      </table>
-    );
+    if (this.state.isCloseHelp) {
+      return;
+    }
+
+    if (!this.state.isCloseHelp) {
+      return (
+        <table className="table grw-search-table search-help m-0">
+          <caption className="text-left text-primary p-2">
+            <h5 className="h6"><i className="icon-magnifier pr-2 mb-2" />{ t('search_help.title') }</h5>
+          </caption>
+          <tbody>
+            <tr>
+              <th className="py-2">
+                <code>word1</code> <code>word2</code><br></br>
+                <small>({ t('search_help.and.syntax help') })</small>
+              </th>
+              <td><h6 className="m-0">{ t('search_help.and.desc', { word1: 'word1', word2: 'word2' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2">
+                <code>&quot;This is GROWI&quot;</code><br></br>
+                <small>({ t('search_help.phrase.syntax help') })</small>
+              </th>
+              <td><h6 className="m-0">{ t('search_help.phrase.desc', { phrase: 'This is GROWI' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2"><code>-keyword</code></th>
+              <td><h6 className="m-0">{ t('search_help.exclude.desc', { word: 'keyword' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2"><code>prefix:/user/</code></th>
+              <td><h6 className="m-0">{ t('search_help.prefix.desc', { path: '/user/' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2"><code>-prefix:/user/</code></th>
+              <td><h6 className="m-0">{ t('search_help.exclude_prefix.desc', { path: '/user/' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2"><code>tag:wiki</code></th>
+              <td><h6 className="m-0">{ t('search_help.tag.desc', { tag: 'wiki' }) }</h6></td>
+            </tr>
+            <tr>
+              <th className="py-2"><code>-tag:wiki</code></th>
+              <td><h6 className="m-0">{ t('search_help.exclude_tag.desc', { tag: 'wiki' }) }</h6></td>
+            </tr>
+          </tbody>
+        </table>
+      );
+    }
   }
   }
 
 
   render() {
   render() {
@@ -124,6 +149,9 @@ class SearchForm extends React.Component {
         placeholder={placeholder}
         placeholder={placeholder}
         helpElement={this.getHelpElement()}
         helpElement={this.getHelpElement()}
         keywordOnInit={this.props.keyword}
         keywordOnInit={this.props.keyword}
+        isCloseHelp={this.state.isCloseHelp}
+        onBlur={this.onBlur}
+        onFocus={this.onFocus}
       />
       />
     );
     );
   }
   }