浏览代码

文本标签无法删除、文本模式下光标问题

liucf 6 年之前
父节点
当前提交
19463d6780
共有 2 个文件被更改,包括 15 次插入7 次删除
  1. 4 3
      src/common/components/EditableSpan/index.jsx
  2. 11 4
      src/common/components/Textarea/index.jsx

+ 4 - 3
src/common/components/EditableSpan/index.jsx

@@ -185,9 +185,10 @@ class EditableSpan extends Component{
         obj.focus();
       }
     }
-    ele = document.activeElement;
-    boxTop = target.innerText?getPageCoordinate(e).boxTop:$(ele).offset().top+30;
-    setSearchLocation(boxTop,ele.offsetLeft)     //搜索框的位置动态获取
+    // 注释掉,放开会影响删除
+    // ele = document.activeElement;
+    // boxTop = target.innerText?getPageCoordinate(e).boxTop:$(ele).offset().top+30;
+    // setSearchLocation(boxTop,ele.offsetLeft)     //搜索框的位置动态获取
   }  
   handleKeyup(e){
     const {boxMark,handleKeydown,i,value,removeId,handleClear,delSingleLable,setSearchLocation} = this.props;

+ 11 - 4
src/common/components/Textarea/index.jsx

@@ -17,7 +17,7 @@ class Textarea extends Component {
     this.$dom = React.createRef();
     this.handleInput = this.handleInput.bind(this);
     this.handleFocus = this.handleFocus.bind(this);
-    //this.handleBlur = this.handleBlur.bind(this);
+    this.handleBlur = this.handleBlur.bind(this);
   }
   handleFocus(){            //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
     const {handleFocus,fuzhen,handleInput} = this.props;
@@ -58,7 +58,7 @@ class Textarea extends Component {
     })
 
     //存值到store
-    handleInput&&handleInput({text});
+    // handleInput&&handleInput({text});
     //右侧推送--延时推送
     clearTimeout(stimer);
     let timer = setTimeout(function(){
@@ -84,7 +84,7 @@ class Textarea extends Component {
   componentDidMount(){
     const {value} = this.props;
     if(value){
-      this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
+      this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerHTML=value||'');
     }
     if(isIE()){
       $(this.$dom.current).onIe8Input(function(e){
@@ -92,6 +92,12 @@ class Textarea extends Component {
       },this);
     }
   }
+  handleBlur(){
+    const {handleInput} = this.props;
+    const text = this.$dom.current.innerText||this.$dom.current.innerHTML;
+    //存值到store
+    handleInput&&handleInput({text});
+  }
   render() {
     const { title } = this.props;
     return (
@@ -102,7 +108,8 @@ class Textarea extends Component {
              onFocus={this.handleFocus}
              ref={this.$dom}
              contentEditable={true}
-             onInput={this.handleInput}>
+             onInput={this.handleInput}
+             onBlur={this.handleBlur}>
         </div>
       </div>
     );