@@ -25,7 +25,7 @@ export default class InputNumber extends Component {
2525
2626 componentWillReceiveProps ( props : Object ) {
2727 if ( props . value != this . props . value ) {
28- this . setState ( { value : props . value } ) ;
28+ this . setState ( { value : Number ( props . value ) } ) ;
2929 }
3030 }
3131
@@ -45,20 +45,24 @@ export default class InputNumber extends Component {
4545 }
4646
4747 onBlur ( ) : void {
48- let value = parseFloat ( this . state . value ) ;
48+ let value = this . state . value ;
4949
50- if ( isNaN ( value ) ) {
51- value = ''
52- } else if ( value > this . props . max ) {
53- value = this . props . max ;
50+ if ( value > this . props . max ) {
51+ value = Number ( this . props . max ) ;
5452 } else if ( value < this . props . min ) {
55- value = this . props . min ;
53+ value = Number ( this . props . min ) ;
5654 }
5755
5856 this . setState ( { value } , this . onChange ) ;
5957 }
6058
6159 onInput ( value : mixed ) : void {
60+ value = Number ( value ) ;
61+
62+ if ( isNaN ( value ) ) {
63+ return ;
64+ }
65+
6266 this . setState ( { value } ) ;
6367 }
6468
@@ -69,18 +73,18 @@ export default class InputNumber extends Component {
6973 }
7074
7175 minDisabled ( ) : boolean {
72- return this . state . value - this . props . step < this . props . min ;
76+ return this . state . value - Number ( this . props . step ) < this . props . min ;
7377 }
7478
7579 maxDisabled ( ) : boolean {
76- return this . state . value + this . props . step > this . props . max ;
80+ return this . state . value + Number ( this . props . step ) > this . props . max ;
7781 }
7882
7983 increase ( ) : void {
8084 const { step, max, disabled } = this . props ;
8185 let { value, inputActive } = this . state ;
8286
83- if ( value + step > max || disabled ) return ;
87+ if ( value + Number ( step ) > max || disabled ) return ;
8488
8589 value = accAdd ( step , value ) ;
8690
@@ -95,7 +99,7 @@ export default class InputNumber extends Component {
9599 const { step, min, disabled } = this . props ;
96100 let { value, inputActive } = this . state ;
97101
98- if ( value - step < min || disabled ) return ;
102+ if ( value - Number ( step ) < min || disabled ) return ;
99103
100104 value = accSub ( value , step ) ;
101105
@@ -123,10 +127,11 @@ export default class InputNumber extends Component {
123127 }
124128
125129 render ( ) : React . Element < any > {
126- const { controls, disabled } = this . props ;
130+ const { controls, disabled, size } = this . props ;
131+ const { value, inputActive } = this . state ;
127132
128133 return (
129- < div style = { this . style ( ) } className = { this . className ( 'el-input-number' , this . props . size && `el-input-number--${ this . props . size } ` , {
134+ < div style = { this . style ( ) } className = { this . className ( 'el-input-number' , size && `el-input-number--${ size } ` , {
130135 'is-disabled' : disabled ,
131136 'is-without-controls' : ! controls
132137 } ) } >
@@ -157,11 +162,11 @@ export default class InputNumber extends Component {
157162 < Input
158163 ref = "input"
159164 className = { this . classNames ( {
160- 'is-active' : this . state . inputActive
165+ 'is-active' : inputActive
161166 } ) }
162- value = { this . state . value }
163- disabled = { this . props . disabled }
164- size = { this . props . size }
167+ value = { value }
168+ disabled = { disabled }
169+ size = { size }
165170 onChange = { this . onInput . bind ( this ) }
166171 onKeyDown = { this . onKeyDown . bind ( this ) }
167172 onBlur = { this . onBlur . bind ( this ) } />
0 commit comments