mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
[Improvement] Stepper: better input experience(#1484)
This commit is contained in:
parent
1f5a409112
commit
a99e73e07e
@ -80,7 +80,6 @@ export default create({
|
|||||||
watch: {
|
watch: {
|
||||||
value(val) {
|
value(val) {
|
||||||
if (val !== '') {
|
if (val !== '') {
|
||||||
val = this.correctValue(+val);
|
|
||||||
if (val !== this.currentValue) {
|
if (val !== this.currentValue) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
}
|
}
|
||||||
@ -101,7 +100,7 @@ export default create({
|
|||||||
|
|
||||||
onInput(event) {
|
onInput(event) {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
this.currentValue = value ? this.correctValue(+value) : value;
|
this.currentValue = Math.min(this.max, value);
|
||||||
event.target.value = this.currentValue;
|
event.target.value = this.currentValue;
|
||||||
this.emitInput();
|
this.emitInput();
|
||||||
},
|
},
|
||||||
@ -122,8 +121,10 @@ export default create({
|
|||||||
onBlur(event) {
|
onBlur(event) {
|
||||||
if (!this.value) {
|
if (!this.value) {
|
||||||
this.currentValue = +this.min;
|
this.currentValue = +this.min;
|
||||||
this.emitInput();
|
} else {
|
||||||
|
this.currentValue = this.correctValue(+this.currentValue);
|
||||||
}
|
}
|
||||||
|
this.emitInput();
|
||||||
this.$emit('blur', event);
|
this.$emit('blur', event);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -64,10 +64,10 @@ test('correct value when value is not correct', () => {
|
|||||||
|
|
||||||
expect(wrapper.emitted('input')).toEqual([
|
expect(wrapper.emitted('input')).toEqual([
|
||||||
[30],
|
[30],
|
||||||
[10],
|
[1],
|
||||||
[''],
|
[0],
|
||||||
[10],
|
[0],
|
||||||
[10],
|
[0],
|
||||||
[30],
|
[30],
|
||||||
[30]
|
[30]
|
||||||
]);
|
]);
|
||||||
@ -83,8 +83,9 @@ test('only allow interger', () => {
|
|||||||
const input = wrapper.find('input');
|
const input = wrapper.find('input');
|
||||||
input.element.value = '1.2';
|
input.element.value = '1.2';
|
||||||
input.trigger('input');
|
input.trigger('input');
|
||||||
|
input.trigger('blur');
|
||||||
|
|
||||||
expect(wrapper.emitted('input')).toEqual([[1]]);
|
expect(wrapper.emitted('input')).toEqual([[1.2], [1]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stepper blur', () => {
|
test('stepper blur', () => {
|
||||||
@ -105,6 +106,6 @@ test('stepper blur', () => {
|
|||||||
input.trigger('input');
|
input.trigger('input');
|
||||||
input.trigger('blur');
|
input.trigger('blur');
|
||||||
|
|
||||||
expect(wrapper.emitted('input')).toEqual([[''], [3]]);
|
expect(wrapper.emitted('input')).toEqual([[5], [0], [3]]);
|
||||||
expect(wrapper.emitted('blur')).toBeTruthy();
|
expect(wrapper.emitted('blur')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user