diff --git a/packages/stepper/index.vue b/packages/stepper/index.vue index 969fd02aa..5921eddb8 100644 --- a/packages/stepper/index.vue +++ b/packages/stepper/index.vue @@ -80,7 +80,6 @@ export default create({ watch: { value(val) { if (val !== '') { - val = this.correctValue(+val); if (val !== this.currentValue) { this.currentValue = val; } @@ -101,7 +100,7 @@ export default create({ onInput(event) { const { value } = event.target; - this.currentValue = value ? this.correctValue(+value) : value; + this.currentValue = Math.min(this.max, value); event.target.value = this.currentValue; this.emitInput(); }, @@ -122,8 +121,10 @@ export default create({ onBlur(event) { if (!this.value) { this.currentValue = +this.min; - this.emitInput(); + } else { + this.currentValue = this.correctValue(+this.currentValue); } + this.emitInput(); this.$emit('blur', event); }, diff --git a/packages/stepper/test/index.spec.js b/packages/stepper/test/index.spec.js index 5379bc94a..fb3c97dfe 100644 --- a/packages/stepper/test/index.spec.js +++ b/packages/stepper/test/index.spec.js @@ -64,10 +64,10 @@ test('correct value when value is not correct', () => { expect(wrapper.emitted('input')).toEqual([ [30], - [10], - [''], - [10], - [10], + [1], + [0], + [0], + [0], [30], [30] ]); @@ -83,8 +83,9 @@ test('only allow interger', () => { const input = wrapper.find('input'); input.element.value = '1.2'; input.trigger('input'); + input.trigger('blur'); - expect(wrapper.emitted('input')).toEqual([[1]]); + expect(wrapper.emitted('input')).toEqual([[1.2], [1]]); }); test('stepper blur', () => { @@ -105,6 +106,6 @@ test('stepper blur', () => { input.trigger('input'); input.trigger('blur'); - expect(wrapper.emitted('input')).toEqual([[''], [3]]); + expect(wrapper.emitted('input')).toEqual([[5], [0], [3]]); expect(wrapper.emitted('blur')).toBeTruthy(); });