Просмотр исходного кода

Merge pull request #3236 from weseek/fix/remain-getHelpElement-in-case-of-mobile

Fix/remain get help element in case of mobile
Yuki Takei 5 лет назад
Родитель
Сommit
2760d700c5
2 измененных файлов с 29 добавлено и 0 удалено
  1. 25 0
      src/client/js/components/SearchForm.jsx
  2. 4 0
      src/client/js/components/SearchTypeahead.jsx

+ 25 - 0
src/client/js/components/SearchForm.jsx

@@ -13,10 +13,13 @@ class SearchForm extends React.Component {
 
 
     this.state = {
     this.state = {
       searchError: null,
       searchError: null,
+      isShownHelp: false,
     };
     };
 
 
     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({
+      isShownHelp: false,
+    });
+
+    this.getHelpElement();
+  }
+
+  onFocus() {
+    this.setState({
+      isShownHelp: true,
+    });
+  }
+
   getHelpElement() {
   getHelpElement() {
     const { t, appContainer } = this.props;
     const { t, appContainer } = this.props;
+    const { isShownHelp } = this.state;
 
 
     const config = appContainer.getConfig();
     const config = appContainer.getConfig();
     const isReachable = config.isSearchServiceReachable;
     const isReachable = config.isSearchServiceReachable;
 
 
+
     if (!isReachable) {
     if (!isReachable) {
       return (
       return (
         <>
         <>
@@ -55,6 +74,10 @@ class SearchForm extends React.Component {
       );
       );
     }
     }
 
 
+    if (!isShownHelp) {
+      return null;
+    }
+
     return (
     return (
       <table className="table grw-search-table search-help m-0">
       <table className="table grw-search-table search-help m-0">
         <caption className="text-left text-primary p-2">
         <caption className="text-left text-primary p-2">
@@ -124,6 +147,8 @@ class SearchForm extends React.Component {
         placeholder={placeholder}
         placeholder={placeholder}
         helpElement={this.getHelpElement()}
         helpElement={this.getHelpElement()}
         keywordOnInit={this.props.keyword}
         keywordOnInit={this.props.keyword}
+        onBlur={this.onBlur}
+        onFocus={this.onFocus}
       />
       />
     );
     );
   }
   }

+ 4 - 0
src/client/js/components/SearchTypeahead.jsx

@@ -222,6 +222,8 @@ class SearchTypeahead extends React.Component {
           renderMenuItemChildren={this.renderMenuItemChildren}
           renderMenuItemChildren={this.renderMenuItemChildren}
           caseSensitive={false}
           caseSensitive={false}
           defaultSelected={defaultSelected}
           defaultSelected={defaultSelected}
+          onBlur={this.props.onBlur}
+          onFocus={this.props.onFocus}
         />
         />
         {resetFormButton}
         {resetFormButton}
       </div>
       </div>
@@ -244,6 +246,8 @@ SearchTypeahead.propTypes = {
   onSearchSuccess: PropTypes.func,
   onSearchSuccess: PropTypes.func,
   onSearchError:   PropTypes.func,
   onSearchError:   PropTypes.func,
   onChange:        PropTypes.func,
   onChange:        PropTypes.func,
+  onBlur:          PropTypes.func,
+  onFocus:         PropTypes.func,
   onSubmit:        PropTypes.func,
   onSubmit:        PropTypes.func,
   onInputChange:   PropTypes.func,
   onInputChange:   PropTypes.func,
   inputName:       PropTypes.string,
   inputName:       PropTypes.string,