瀏覽代碼

Merge branch 'dev5.3.2' of http://192.168.2.236:10080/zhouna/newICSS into dev5.3.2

luolei 5 年之前
父節點
當前提交
3746fd1f6c
共有 1 個文件被更改,包括 16 次插入5 次删除
  1. 16 5
      src/common/components/InlineTag/index.jsx

+ 16 - 5
src/common/components/InlineTag/index.jsx

@@ -1,7 +1,6 @@
 import React, { Component } from "react";
 import style from "./index.less";
 import classNames from 'classnames';
-import {handleEnter} from '@utils/tools.js';
 /***
  * 标签组件
  * author:zn@2018-11-08
@@ -27,6 +26,10 @@ class InlineTag extends Component {
   }
   handleInput(e){       //输入时保存临时值,在修改灰显为黑色时判断用
     e.stopPropagation();
+    const value = e.target.innerText;
+    this.setState({
+      value:value
+    })
   }
   handleBlur(e){         //鼠标离开是保存值到store中
     e.stopPropagation(); //不阻止会触发外层div的失焦事件
@@ -56,7 +59,7 @@ class InlineTag extends Component {
   }
   getStyle(){
     const {hideTag,placeholder} = this.props;
-    const value = this.$span.current&&this.$span.current.innerText.trim();
+    const value = this.state.value;//this.$span.current&&this.$span.current.innerText.trim();
     if(hideTag){
       if(value){
         return classNames(style['selected-no-tag']);
@@ -90,9 +93,18 @@ class InlineTag extends Component {
     const spanWidth = window.getComputedStyle(this.$span.current).width;
     this.$span.current.style.minWidth=spanWidth;
   }
+  componentWillReceiveProps(nextProps){
+    if((nextProps.placeholder == this.props.placeholder)&&(nextProps.value == this.props.value)){
+      return
+    }
+    this.setState({
+      placeholder:nextProps.placeholder,
+      value:nextProps.value
+    })
+  }
   render(){
-    const {prefix,suffix} = this.props;
-    const {placeholder,value} = this.state;
+    const {prefix,suffix,value} = this.props;
+    const {placeholder} = this.state;
     return <div className={this.getStyle()}
                 onClick={this.handleFixClick}>
                 <span>{prefix}</span>
@@ -102,7 +114,6 @@ class InlineTag extends Component {
                       onInput={this.handleInput}
                       onFocus={this.handleFocus}
                       onClick={(e)=>{e.stopPropagation();}}
-                      onKeyDown={handleEnter}
                       ref={this.$span}>&nbsp;{value||placeholder}</span>
                 <span>{suffix}</span>
             </div>;