|
@@ -17,7 +17,7 @@ class Textarea extends Component {
|
|
this.$dom = React.createRef();
|
|
this.$dom = React.createRef();
|
|
this.handleInput = this.handleInput.bind(this);
|
|
this.handleInput = this.handleInput.bind(this);
|
|
this.handleFocus = this.handleFocus.bind(this);
|
|
this.handleFocus = this.handleFocus.bind(this);
|
|
- this.handleBlur = this.handleBlur.bind(this);
|
|
|
|
|
|
+ //this.handleBlur = this.handleBlur.bind(this);
|
|
this.handleKeydown = this.handleKeydown.bind(this);
|
|
this.handleKeydown = this.handleKeydown.bind(this);
|
|
}
|
|
}
|
|
handleFocus(){ //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
|
|
handleFocus(){ //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
|
|
@@ -36,7 +36,7 @@ class Textarea extends Component {
|
|
const text = e.target.innerText || e.target.innerHTML;
|
|
const text = e.target.innerText || e.target.innerHTML;
|
|
const stimer = this.state.timer;
|
|
const stimer = this.state.timer;
|
|
if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
|
|
if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
|
|
- e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
|
|
|
|
|
|
+ e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
|
|
e.target.blur();
|
|
e.target.blur();
|
|
Notify.error(config.limitText);
|
|
Notify.error(config.limitText);
|
|
if(overFlag){
|
|
if(overFlag){
|
|
@@ -59,7 +59,7 @@ class Textarea extends Component {
|
|
})
|
|
})
|
|
|
|
|
|
//存值到store
|
|
//存值到store
|
|
- // handleInput&&handleInput({text});
|
|
|
|
|
|
+ handleInput&&handleInput({text});
|
|
//右侧推送--延时推送
|
|
//右侧推送--延时推送
|
|
clearTimeout(stimer);
|
|
clearTimeout(stimer);
|
|
let timer = setTimeout(function(){
|
|
let timer = setTimeout(function(){
|
|
@@ -70,6 +70,14 @@ class Textarea extends Component {
|
|
timer
|
|
timer
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ handleKeydown(e){
|
|
|
|
+ const {boxMark} = this.props;
|
|
|
|
+ const ev = e||window.event;
|
|
|
|
+ if(+boxMark==1){
|
|
|
|
+ //禁止回车事件
|
|
|
|
+ if(ev.keyCode==13){return false;}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
shouldComponentUpdate(next){
|
|
shouldComponentUpdate(next){
|
|
if(JSON.stringify(next) == JSON.stringify(this.props)){
|
|
if(JSON.stringify(next) == JSON.stringify(this.props)){
|
|
return false;
|
|
return false;
|
|
@@ -85,7 +93,7 @@ class Textarea extends Component {
|
|
componentDidMount(){
|
|
componentDidMount(){
|
|
const {value} = this.props;
|
|
const {value} = this.props;
|
|
if(value){
|
|
if(value){
|
|
- this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerHTML=value||'');
|
|
|
|
|
|
+ this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
|
|
}
|
|
}
|
|
if(isIE()){
|
|
if(isIE()){
|
|
$(this.$dom.current).onIe8Input(function(e){
|
|
$(this.$dom.current).onIe8Input(function(e){
|
|
@@ -93,20 +101,6 @@ class Textarea extends Component {
|
|
},this);
|
|
},this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- handleBlur(){
|
|
|
|
- const {handleInput} = this.props;
|
|
|
|
- const text = this.$dom.current.innerText||this.$dom.current.innerHTML;
|
|
|
|
- //存值到store
|
|
|
|
- handleInput&&handleInput({text});
|
|
|
|
- }
|
|
|
|
- handleKeydown(e){
|
|
|
|
- const {boxMark} = this.props;
|
|
|
|
- const ev = e||window.event;
|
|
|
|
- if(+boxMark==1){
|
|
|
|
- //禁止回车事件
|
|
|
|
- if(ev.keyCode==13){return false;}
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
render() {
|
|
render() {
|
|
const { title } = this.props;
|
|
const { title } = this.props;
|
|
return (
|
|
return (
|
|
@@ -118,7 +112,6 @@ class Textarea extends Component {
|
|
ref={this.$dom}
|
|
ref={this.$dom}
|
|
contentEditable={true}
|
|
contentEditable={true}
|
|
onInput={this.handleInput}
|
|
onInput={this.handleInput}
|
|
- onBlur={this.handleBlur}
|
|
|
|
onkeydown={this.handleKeydown}>
|
|
onkeydown={this.handleKeydown}>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|