feat(Stepper): add allow-empty prop (#6759)

* feat(Stepper): add allow-empty prop

* fix: remove test only
This commit is contained in:
neverland 2020-07-11 10:52:28 +08:00 committed by GitHub
parent 709b822c06
commit 060b1fb717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View File

@ -129,6 +129,7 @@ export default {
| show-plus `v2.1.2` | Whether to show plus button | _boolean_ | `true` | | show-plus `v2.1.2` | Whether to show plus button | _boolean_ | `true` |
| show-minus `v2.1.2` | Whether to show minus button | _boolean_ | `true` | | show-minus `v2.1.2` | Whether to show minus button | _boolean_ | `true` |
| long-press `v2.4.3` | Whether to allow long press | _boolean_ | `true` | | long-press `v2.4.3` | Whether to allow long press | _boolean_ | `true` |
| allow-empty `v2.9.1` | Whether to allow the input to be empty | _boolean_ | `false` |
### Events ### Events

View File

@ -155,6 +155,7 @@ export default {
| show-plus `v2.1.2` | 是否显示增加按钮 | _boolean_ | `true` | | show-plus `v2.1.2` | 是否显示增加按钮 | _boolean_ | `true` |
| show-minus `v2.1.2` | 是否显示减少按钮 | _boolean_ | `true` | | show-minus `v2.1.2` | 是否显示减少按钮 | _boolean_ | `true` |
| long-press `v2.4.3` | 是否开启长按手势 | _boolean_ | `true` | | long-press `v2.4.3` | 是否开启长按手势 | _boolean_ | `true` |
| allow-empty `v2.9.1` | 是否允许输入的值为空 | _boolean_ | `false` |
### Events ### Events

View File

@ -28,6 +28,7 @@ export default createComponent({
theme: String, theme: String,
integer: Boolean, integer: Boolean,
disabled: Boolean, disabled: Boolean,
allowEmpty: Boolean,
inputWidth: [Number, String], inputWidth: [Number, String],
buttonSize: [Number, String], buttonSize: [Number, String],
asyncChange: Boolean, asyncChange: Boolean,
@ -154,6 +155,10 @@ export default createComponent({
}, },
format(value) { format(value) {
if (this.allowEmpty && value === '') {
return value;
}
value = this.formatNumber(value); value = this.formatNumber(value);
// format range // format range

View File

@ -387,3 +387,20 @@ test('placeholder prop', () => {
}); });
expect(wrapper.find('.van-stepper__input')).toMatchSnapshot(); expect(wrapper.find('.van-stepper__input')).toMatchSnapshot();
}); });
test('allow-empty prop', () => {
const wrapper = mount(Stepper, {
propsData: {
value: '',
allowEmpty: true,
},
});
const input = wrapper.find('input');
input.trigger('blur');
expect(wrapper.emitted('input')).toBeFalsy();
wrapper.setProps({ allowEmpty: false });
input.trigger('blur');
expect(wrapper.emitted('input')[0][0]).toEqual(1);
});