[Improvement] Stepper blur (#1316)

This commit is contained in:
neverland 2018-06-22 15:46:51 +08:00 committed by GitHub
parent 6204892ad7
commit 1da6a30f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -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 | - |

View File

@ -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);

View File

@ -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();
});

View File

@ -67,3 +67,4 @@ export default {
| overlimit | 点击不可用的按钮时触发 | - |
| plus | 点击增加按钮时触发 | - |
| minus | 点击减少按钮时触发 | - |
| blur | 输入框失焦时触发 | - |