Skip to content

Commit ab83ad5

Browse files
author
城管大队长
authored
Merge pull request #114 from ant-mini-program/fix-stepper
fix: fix #111
2 parents f17baf0 + e5be26a commit ab83ad5

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

src/stepper/demo/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Page({
22
data: {
33
value: 8,
44
},
5-
callBackFn(value){
6-
console.log(value);
5+
callBackFn(value) {
6+
console.log(value);
77
},
88
modifyValue() {
99
this.setData({
10-
value: this.data.value + 1,
10+
value: 9,
1111
});
12-
}
12+
},
1313
});

src/stepper/index.axml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
max="{{max}}"
55
min="{{min}}"
66
onChange="{{callBackFn}}"
7-
readOnly="{{readOnly}}"
87
step="{{step}}"
98
disabled="{{disabled || readOnly}}"
109
>
1110
<view class="am-stepper-reduce" style="opacity:{{opaReduce}}" data-type="reduce" onTap="changeFn" />
1211
<input
1312
class="am-stepper-input"
1413
style="display:{{showNumber ? 'inline-block' : 'none'}}"
15-
value={{value}}
16-
onBlur="resetFn"
14+
value="{{value}}"
15+
onBlur="onBlur"
16+
disabled="{{disabled || readOnly}}"
1717
type="number"
1818
/>
1919
<view class="am-stepper-add" style="opacity:{{opaAdd}}" data-type="add" onTap="changeFn" />

src/stepper/index.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,31 @@ Component({
2020
value: Math.min(Math.max(min, value), max),
2121
});
2222
},
23-
didUpdate(preProps, preData) {
23+
didUpdate(preProps) {
2424
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);
2627
this.setData({
27-
value: Math.min(Math.max(min, value), max),
28+
value: newValue,
2829
});
30+
this.resetFn(newValue);
2931
}
3032
},
3133
methods: {
3234
changeFn(ev) {
3335
const { min, max, onChange, disabled, readOnly, step } = this.props;
3436
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;
3739
if (!enable) {
38-
if (evType === "reduce") {
40+
if (evType === 'reduce') {
3941
if (value > min) {
4042
opaAdd = 1;
4143
value = Math.max(min, value - step);
4244
opaReduce = value === min ? 0.4 : 1;
4345
}
4446
} else {
47+
/* eslint-disable no-lonely-if */
4548
if (value < max) {
4649
opaReduce = 1;
4750
value = Math.min(value + step, max);
@@ -56,16 +59,19 @@ Component({
5659
onChange(value);
5760
}
5861
},
59-
resetFn(ev) {
62+
onBlur(event) {
63+
const { value } = event.detail;
64+
this.resetFn(value);
65+
},
66+
resetFn(value) {
6067
const { max, min, onChange } = this.props;
61-
const value = ev.detail.value;
6268
let calculatedVal = value;
6369
let opaAdd = 1;
6470
let opaReduce = 1;
65-
if (value > max) {
71+
if (value >= max) {
6672
calculatedVal = max;
6773
opaAdd = 0.4;
68-
} else if (value < min) {
74+
} else if (value <= min) {
6975
calculatedVal = min;
7076
opaReduce = 0.4;
7177
}
@@ -76,5 +82,5 @@ Component({
7682
});
7783
onChange(calculatedVal);
7884
},
79-
}
80-
})
85+
},
86+
});

src/vtabs/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Component({
1515
tabBarInactiveBgColor: '#f8f8f8',
1616
tabBarlineColor: '#108ee9',
1717
onTabClick: () => {},
18-
onScrollBar: () => {}
18+
onScrollBar: () => {},
1919
},
2020
didMount() {
2121
const { tabs } = this.props;
@@ -57,7 +57,7 @@ Component({
5757
const { anchor, index } = e.target.dataset;
5858

5959
if (!this.isScrolling || !this.props.swipeable) {
60-
if(this.data.current !== index) {
60+
if (this.data.current !== index) {
6161
this.props.onTabClick(index);
6262
}
6363
this.setData({
@@ -76,7 +76,7 @@ Component({
7676
tabTop = (current - 5) * 55;
7777
}
7878
if (this.data.current !== current) {
79-
this.props.onScrollBar(current)
79+
this.props.onScrollBar(current);
8080
}
8181
this.setData({
8282
tabTop,

0 commit comments

Comments
 (0)