mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] Stepper blur (#1316)
This commit is contained in:
parent
6204892ad7
commit
1da6a30f19
@ -63,4 +63,5 @@ export default {
|
||||
| change | Triggered when value change | value: current value |
|
||||
| overlimit | Triggered when click disabled button | - |
|
||||
| plus | Triggered when click plus button | - |
|
||||
| minus | Triggered when click minus button | - |
|
||||
| minus | Triggered when click minus button | - |
|
||||
| blur | Triggered when input blured | - |
|
||||
|
@ -11,6 +11,7 @@
|
||||
:disabled="disabled || disableInput"
|
||||
@input="onInput"
|
||||
@keypress="onKeypress"
|
||||
@blur="onBlur"
|
||||
>
|
||||
<button
|
||||
:class="b('plus', { disabled: plusDisabled })"
|
||||
@ -121,6 +122,14 @@ export default create({
|
||||
}
|
||||
},
|
||||
|
||||
onBlur(event) {
|
||||
if (!this.value) {
|
||||
this.currentValue = +this.min;
|
||||
this.emitInput();
|
||||
}
|
||||
this.$emit('blur', event);
|
||||
},
|
||||
|
||||
emitInput() {
|
||||
this.$emit('input', this.currentValue);
|
||||
this.$emit('change', this.currentValue);
|
||||
|
@ -92,3 +92,25 @@ test('only allow interger', () => {
|
||||
|
||||
expect(fn.mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('stepper blur', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
value: 5,
|
||||
min: 3
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.vm.$on('input', value => {
|
||||
wrapper.setProps({ value });
|
||||
});
|
||||
|
||||
const input = wrapper.find('input');
|
||||
input.trigger('blur');
|
||||
input.element.value = '';
|
||||
input.trigger('input');
|
||||
input.trigger('blur');
|
||||
|
||||
expect(wrapper.emitted('input')).toEqual([[''], [3]]);
|
||||
expect(wrapper.emitted('blur')).toBeTruthy();
|
||||
});
|
||||
|
@ -67,3 +67,4 @@ export default {
|
||||
| overlimit | 点击不可用的按钮时触发 | - |
|
||||
| plus | 点击增加按钮时触发 | - |
|
||||
| minus | 点击减少按钮时触发 | - |
|
||||
| blur | 输入框失焦时触发 | - |
|
||||
|
Loading…
x
Reference in New Issue
Block a user