[bugfix] Stepper: integer in android (#1482)

This commit is contained in:
neverland 2018-07-13 15:40:23 +08:00 committed by GitHub
parent 6977cf8a80
commit 13f7a5d57f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 20 deletions

View File

@ -10,7 +10,6 @@
:value="currentValue" :value="currentValue"
:disabled="disabled || disableInput" :disabled="disabled || disableInput"
@input="onInput" @input="onInput"
@keypress="onKeypress"
@blur="onBlur" @blur="onBlur"
> >
<button <button
@ -91,9 +90,13 @@ export default create({
methods: { methods: {
correctValue(value) { correctValue(value) {
return isNaN(value) if (isNaN(value)) {
? this.min return this.min;
: Math.max(this.min, Math.min(this.max, value)); }
value = Math.max(this.min, Math.min(this.max, value));
return this.integer ? Math.floor(value) : value;
}, },
onInput(event) { onInput(event) {
@ -116,12 +119,6 @@ export default create({
this.$emit(type); this.$emit(type);
}, },
onKeypress(event) {
if (this.integer && event.keyCode === 46) {
event.preventDefault();
}
},
onBlur(event) { onBlur(event) {
if (!this.value) { if (!this.value) {
this.currentValue = +this.min; this.currentValue = +this.min;

View File

@ -80,17 +80,11 @@ test('only allow interger', () => {
} }
}); });
const fn = jest.fn(); const input = wrapper.find('input');
wrapper.vm.onKeypress({ input.element.value = '1.2';
keyCode: 46, input.trigger('input');
preventDefault: fn
});
wrapper.vm.onKeypress({
keyCode: 45,
preventDefault: fn
});
expect(fn.mock.calls.length).toEqual(1); expect(wrapper.emitted('input')).toEqual([[1]]);
}); });
test('stepper blur', () => { test('stepper blur', () => {