@@ -4,35 +4,33 @@ import './Input.css';
44const classNames = require ( 'classnames' ) ;
55
66export class Input extends Component {
7- constructor ( props ) {
8- super ( props ) ;
9-
10- this . state = {
11- value : this . props . defaultValue ,
12- } ;
13- }
14-
157 onChange ( e ) {
168 if ( this . props . maxlength && ( e . target . value || '' ) . length > this . props . maxlength ) {
179 if ( this . props . onMaxLengthExceed instanceof Function )
1810 this . props . onMaxLengthExceed ( ) ;
11+
12+ this . input . value = ( e . target . value || '' ) . substring ( 0 , this . props . maxlength ) ;
1913 return ;
2014 }
2115
22- this . setState ( {
23- value : e . target . value
24- } ) ;
2516 if ( this . props . onChange instanceof Function )
2617 this . props . onChange ( e ) ;
2718
2819 if ( this . props . multiline === true ) {
2920 if ( this . props . autoHeight === true ) {
30- e . target . style . height = this . props . minHeight + 'px' ;
21+ if ( e . target . style . height !== this . props . minHeight + 'px' ) {
22+ e . target . style . height = this . props . minHeight + 'px' ;
23+ }
3124
25+ let height ;
3226 if ( e . target . scrollHeight <= this . props . maxHeight )
33- e . target . style . height = e . target . scrollHeight + 'px' ;
27+ height = e . target . scrollHeight + 'px' ;
3428 else
35- e . target . style . height = this . props . maxHeight + 'px' ;
29+ height = this . props . maxHeight + 'px' ;
30+
31+ if ( e . target . style . height !== height ) {
32+ e . target . style . height = height ;
33+ }
3634 }
3735 }
3836 }
@@ -42,7 +40,11 @@ export class Input extends Component {
4240 FAKE_EVENT : true ,
4341 target : this . input ,
4442 } ;
45- this . input . value = '' ;
43+
44+ if ( this . input . value ) {
45+ this . input . value = '' ;
46+ }
47+
4648 this . onChange ( event ) ;
4749 }
4850
@@ -71,7 +73,7 @@ export class Input extends Component {
7173 type = { this . props . type }
7274 className = { classNames ( 'rce-input' ) }
7375 placeholder = { this . props . placeholder }
74- value = { this . state . value }
76+ defaultValue = { this . props . defaultValue }
7577 style = { this . props . inputStyle }
7678 onChange = { this . onChange . bind ( this ) }
7779 onCopy = { this . props . onCopy }
@@ -95,7 +97,7 @@ export class Input extends Component {
9597 type = { this . props . type }
9698 className = { classNames ( 'rce-input' , 'rce-input-textarea' ) }
9799 placeholder = { this . props . placeholder }
98- value = { this . state . value }
100+ defaultValue = { this . props . defaultValue }
99101 style = { this . props . inputStyle }
100102 onChange = { this . onChange . bind ( this ) }
101103 onCopy = { this . props . onCopy }
0 commit comments