@@ -20,28 +20,31 @@ Component({
20
20
value : Math . min ( Math . max ( min , value ) , max ) ,
21
21
} ) ;
22
22
} ,
23
- didUpdate ( preProps , preData ) {
23
+ didUpdate ( preProps ) {
24
24
const { value, min, max } = this . props ;
25
- if ( preProps . value !== this . props . value ) {
25
+ if ( preProps . value !== value ) {
26
+ const newValue = Math . min ( Math . max ( min , value ) , max ) ;
26
27
this . setData ( {
27
- value : Math . min ( Math . max ( min , value ) , max ) ,
28
+ value : newValue ,
28
29
} ) ;
30
+ this . resetFn ( newValue ) ;
29
31
}
30
32
} ,
31
33
methods : {
32
34
changeFn ( ev ) {
33
35
const { min, max, onChange, disabled, readOnly, step } = this . props ;
34
36
const evType = ev . target . dataset . type ;
35
- let { opaReduce, opaAdd, value } = this . data ;
36
- let enable = disabled ? disabled : readOnly ;
37
+ let { opaReduce, opaAdd, value } = this . data ;
38
+ const enable = disabled || readOnly ;
37
39
if ( ! enable ) {
38
- if ( evType === " reduce" ) {
40
+ if ( evType === ' reduce' ) {
39
41
if ( value > min ) {
40
42
opaAdd = 1 ;
41
43
value = Math . max ( min , value - step ) ;
42
44
opaReduce = value === min ? 0.4 : 1 ;
43
45
}
44
46
} else {
47
+ /* eslint-disable no-lonely-if */
45
48
if ( value < max ) {
46
49
opaReduce = 1 ;
47
50
value = Math . min ( value + step , max ) ;
@@ -56,16 +59,19 @@ Component({
56
59
onChange ( value ) ;
57
60
}
58
61
} ,
59
- resetFn ( ev ) {
62
+ onBlur ( event ) {
63
+ const { value } = event . detail ;
64
+ this . resetFn ( value ) ;
65
+ } ,
66
+ resetFn ( value ) {
60
67
const { max, min, onChange } = this . props ;
61
- const value = ev . detail . value ;
62
68
let calculatedVal = value ;
63
69
let opaAdd = 1 ;
64
70
let opaReduce = 1 ;
65
- if ( value > max ) {
71
+ if ( value >= max ) {
66
72
calculatedVal = max ;
67
73
opaAdd = 0.4 ;
68
- } else if ( value < min ) {
74
+ } else if ( value <= min ) {
69
75
calculatedVal = min ;
70
76
opaReduce = 0.4 ;
71
77
}
@@ -76,5 +82,5 @@ Component({
76
82
} ) ;
77
83
onChange ( calculatedVal ) ;
78
84
} ,
79
- }
80
- } )
85
+ } ,
86
+ } ) ;
0 commit comments