@@ -4,35 +4,33 @@ import './Input.css';
4
4
const classNames = require ( 'classnames' ) ;
5
5
6
6
export class Input extends Component {
7
- constructor ( props ) {
8
- super ( props ) ;
9
-
10
- this . state = {
11
- value : this . props . defaultValue ,
12
- } ;
13
- }
14
-
15
7
onChange ( e ) {
16
8
if ( this . props . maxlength && ( e . target . value || '' ) . length > this . props . maxlength ) {
17
9
if ( this . props . onMaxLengthExceed instanceof Function )
18
10
this . props . onMaxLengthExceed ( ) ;
11
+
12
+ this . input . value = ( e . target . value || '' ) . substring ( 0 , this . props . maxlength ) ;
19
13
return ;
20
14
}
21
15
22
- this . setState ( {
23
- value : e . target . value
24
- } ) ;
25
16
if ( this . props . onChange instanceof Function )
26
17
this . props . onChange ( e ) ;
27
18
28
19
if ( this . props . multiline === true ) {
29
20
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
+ }
31
24
25
+ let height ;
32
26
if ( e . target . scrollHeight <= this . props . maxHeight )
33
- e . target . style . height = e . target . scrollHeight + 'px' ;
27
+ height = e . target . scrollHeight + 'px' ;
34
28
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
+ }
36
34
}
37
35
}
38
36
}
@@ -42,7 +40,11 @@ export class Input extends Component {
42
40
FAKE_EVENT : true ,
43
41
target : this . input ,
44
42
} ;
45
- this . input . value = '' ;
43
+
44
+ if ( this . input . value ) {
45
+ this . input . value = '' ;
46
+ }
47
+
46
48
this . onChange ( event ) ;
47
49
}
48
50
@@ -71,7 +73,7 @@ export class Input extends Component {
71
73
type = { this . props . type }
72
74
className = { classNames ( 'rce-input' ) }
73
75
placeholder = { this . props . placeholder }
74
- value = { this . state . value }
76
+ defaultValue = { this . props . defaultValue }
75
77
style = { this . props . inputStyle }
76
78
onChange = { this . onChange . bind ( this ) }
77
79
onCopy = { this . props . onCopy }
@@ -95,7 +97,7 @@ export class Input extends Component {
95
97
type = { this . props . type }
96
98
className = { classNames ( 'rce-input' , 'rce-input-textarea' ) }
97
99
placeholder = { this . props . placeholder }
98
- value = { this . state . value }
100
+ defaultValue = { this . props . defaultValue }
99
101
style = { this . props . inputStyle }
100
102
onChange = { this . onChange . bind ( this ) }
101
103
onCopy = { this . props . onCopy }
0 commit comments