From b042082322c99f1d51ada6d6ba9d0237c274a5eb Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 3 Dec 2019 18:53:47 +0800 Subject: [PATCH] feat(Stepper): add disable-plus & disable-minus props (#5180) --- src/stepper/README.md | 2 ++ src/stepper/README.zh-CN.md | 2 ++ src/stepper/index.js | 10 ++++++++-- src/stepper/test/index.spec.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/stepper/README.md b/src/stepper/README.md index c0ac195d7..9e808df39 100644 --- a/src/stepper/README.md +++ b/src/stepper/README.md @@ -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 diff --git a/src/stepper/README.zh-CN.md b/src/stepper/README.zh-CN.md index fed358fa9..fb6211ff4 100644 --- a/src/stepper/README.zh-CN.md +++ b/src/stepper/README.zh-CN.md @@ -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 diff --git a/src/stepper/index.js b/src/stepper/index.js index 44a5a6655..3e61ea496 100644 --- a/src/stepper/index.js +++ b/src/stepper/index.js @@ -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() { diff --git a/src/stepper/test/index.spec.js b/src/stepper/test/index.spec.js index a5a2deff2..29748616e 100644 --- a/src/stepper/test/index.spec.js +++ b/src/stepper/test/index.spec.js @@ -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: {