mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
[bugfix] Stepper: integer in android (#1482)
This commit is contained in:
parent
6977cf8a80
commit
13f7a5d57f
@ -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;
|
||||||
|
@ -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', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user