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"
|
||||
:disabled="disabled || disableInput"
|
||||
@input="onInput"
|
||||
@keypress="onKeypress"
|
||||
@blur="onBlur"
|
||||
>
|
||||
<button
|
||||
@ -91,9 +90,13 @@ export default create({
|
||||
|
||||
methods: {
|
||||
correctValue(value) {
|
||||
return isNaN(value)
|
||||
? this.min
|
||||
: Math.max(this.min, Math.min(this.max, value));
|
||||
if (isNaN(value)) {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
value = Math.max(this.min, Math.min(this.max, value));
|
||||
|
||||
return this.integer ? Math.floor(value) : value;
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
@ -116,12 +119,6 @@ export default create({
|
||||
this.$emit(type);
|
||||
},
|
||||
|
||||
onKeypress(event) {
|
||||
if (this.integer && event.keyCode === 46) {
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
onBlur(event) {
|
||||
if (!this.value) {
|
||||
this.currentValue = +this.min;
|
||||
|
@ -80,17 +80,11 @@ test('only allow interger', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const fn = jest.fn();
|
||||
wrapper.vm.onKeypress({
|
||||
keyCode: 46,
|
||||
preventDefault: fn
|
||||
});
|
||||
wrapper.vm.onKeypress({
|
||||
keyCode: 45,
|
||||
preventDefault: fn
|
||||
});
|
||||
const input = wrapper.find('input');
|
||||
input.element.value = '1.2';
|
||||
input.trigger('input');
|
||||
|
||||
expect(fn.mock.calls.length).toEqual(1);
|
||||
expect(wrapper.emitted('input')).toEqual([[1]]);
|
||||
});
|
||||
|
||||
test('stepper blur', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user