Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/stepper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/stepper/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export default createComponent({
showMinus: {
type: Boolean,
default: true
},
disablePlus: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接写成 disablePlus: Boolean

type: Boolean
},
disableMinus: {
type: Boolean
}
},

Expand All @@ -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() {
Expand Down
29 changes: 29 additions & 0 deletions src/stepper/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down