瀏覽代碼

ie8搜索单个文字删除报错问题

Luolei 6 年之前
父節點
當前提交
db268fc6f4
共有 1 個文件被更改,包括 18 次插入10 次删除
  1. 18 10
      src/common/components/SearchOption/index.jsx

+ 18 - 10
src/common/components/SearchOption/index.jsx

@@ -18,6 +18,8 @@ class SearchOption extends React.Component {
         }
         this.textInput = React.createRef();
         this.handleClearVal = this.handleClearVal.bind(this);
+        this.handleFocus = this.handleFocus.bind(this);
+        this.handleBlur = this.handleBlur.bind(this);
     }
     
     /*componentWillReceiveProps(nextProps){
@@ -47,19 +49,31 @@ class SearchOption extends React.Component {
         handleChangeValue('');
     }
     handleInput(e){
+      const { handleChangeValue } = this.props;
       if((e.target.value).trim() != ''){
-          this.props.handleChangeValue(e.target.value);
+          handleChangeValue(e.target.value);
           this.setState({
               val:e.target.value,
               show:true
           })
       }else{
-          this.handleClearVal()
+          // this.handleClearVal()
           this.setState({
               show:false
           })
+          return;
       }
     }
+    handleFocus(){
+      if(this.state.val.trim() != ''){
+        return;
+      }else{
+          this.setState({border:true})
+      }
+    }
+    handleBlur(){
+      this.setState({border:false,val:''})
+    }
     render() {
         const { children,visible } = this.props;
         const { show } = this.state;
@@ -72,14 +86,8 @@ class SearchOption extends React.Component {
                     type="text"
                     maxLength="30"
                     ref={this.textInput}
-                    onFocus={()=>{
-                        if(this.state.val.trim() != ''){
-                            
-                        }else{
-                            this.setState({border:true})
-                        }
-                    }}
-                    onBlur={()=>{this.setState({border:false,val:''})}}
+                    onFocus={this.handleFocus}
+                    onBlur={this.handleBlur}
                     onInput={(e) => { 
                         this.handleInput(e)
                     }}