feat(Stepper): add disable-plus & disable-minus props (#5180)

This commit is contained in:
Jake 2019-12-03 18:53:47 +08:00 committed by 陈嘉涵
parent 68164da604
commit b042082322
4 changed files with 41 additions and 2 deletions

View File

@ -114,6 +114,8 @@ export default {
| show-plus | Whether to show plus button | *boolean* | `true` | 2.1.2 |
| show-minus | Whether to show minus button | *boolean* | `true` | 2.1.2 |
| decimal-length | Decimal length | *number* | - | 2.2.1 |
| disable-plus | Whether to disable plus button | *boolean* | - | 2.3.0 |
| disable-minus | Whether to disable minus button | *boolean* | - | 2.3.0 |
### Events

View File

@ -136,6 +136,8 @@ export default {
| show-plus | 是否显示增加按钮 | *boolean* | `true` | 2.1.2 |
| show-minus | 是否显示减少按钮 | *boolean* | `true` | 2.1.2 |
| decimal-length | 固定显示的小数位数 | *number* | - | 2.2.1 |
| disable-plus | 是否禁用增加按钮 | *boolean* | - | 2.3.0 |
| disable-minus | 是否禁用减少按钮 | *boolean* | - | 2.3.0 |
### Events

View File

@ -54,6 +54,12 @@ export default createComponent({
showMinus: {
type: Boolean,
default: true
},
disablePlus: {
type: Boolean
},
disableMinus: {
type: Boolean
}
},
@ -72,11 +78,11 @@ export default createComponent({
computed: {
minusDisabled() {
return this.disabled || this.currentValue <= this.min;
return this.disabled || this.disableMinus || this.currentValue <= this.min;
},
plusDisabled() {
return this.disabled || this.currentValue >= this.max;
return this.disabled || this.disablePlus || this.currentValue >= this.max;
},
inputStyle() {

View File

@ -19,6 +19,35 @@ test('disable stepper input', () => {
expect(wrapper).toMatchSnapshot();
});
test('disable button', async () => {
const wrapper = mount(Stepper, {
propsData: {
value: 5
}
});
const plus = wrapper.find('.van-stepper__plus');
const minus = wrapper.find('.van-stepper__minus');
minus.trigger('click');
expect(wrapper.emitted('overlimit')).toBeFalsy();
expect(wrapper.emitted('minus')).toBeTruthy();
expect(wrapper.emitted('change')[0]).toEqual([4, { name: '' }]);
wrapper.setProps({
disablePlus: true,
disableMinus: true
});
await later();
minus.trigger('click');
expect(wrapper.emitted('overlimit')[0][0]).toBe('minus');
plus.trigger('click');
expect(wrapper.emitted('overlimit')[1][0]).toBe('plus');
});
test('click button', () => {
const wrapper = mount(Stepper, {
propsData: {