From d19f676953d53220af7cf537b878d2534a113957 Mon Sep 17 00:00:00 2001 From: Waiter Date: Fri, 13 Dec 2019 10:53:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(Stepper):=20should=20format=20value=20when?= =?UTF-8?q?=20max=E3=80=81min=20changed=20=20(#5257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stepper/index.js | 12 +++++++ src/stepper/test/index.spec.js | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/stepper/index.js b/src/stepper/index.js index 21d2abc14..1a14f14c6 100644 --- a/src/stepper/index.js +++ b/src/stepper/index.js @@ -114,6 +114,11 @@ export default createComponent({ } }, + max: 'check', + min: 'check', + integer: 'check', + decimalLength: 'check', + currentValue(val) { this.$emit('input', val); this.$emit('change', val, { name: this.name }); @@ -121,6 +126,13 @@ export default createComponent({ }, methods: { + check() { + const val = this.format(this.currentValue); + if (!equal(val, this.currentValue)) { + this.currentValue = val; + } + }, + // filter illegal characters filter(value) { value = String(value).replace(/[^0-9.-]/g, ''); diff --git a/src/stepper/test/index.spec.js b/src/stepper/test/index.spec.js index 29748616e..2b423e2c1 100644 --- a/src/stepper/test/index.spec.js +++ b/src/stepper/test/index.spec.js @@ -271,3 +271,61 @@ test('name prop', () => { plus.trigger('click'); expect(wrapper.emitted('change')[1][1]).toEqual({ name: 'name' }); }); + +test('change min and max', async () => { + const wrapper = mount(Stepper, { + propsData: { + value: 1 + } + }); + + wrapper.setProps({ + min: 10, + }); + + await later(); + + expect(wrapper.emitted('input')[0][0]).toEqual(10); + + wrapper.setProps({ + min: 3, + max: 8, + }); + + await later(); + + expect(wrapper.emitted('input')[1][0]).toEqual(8); +}); + + +test('change decimal-length', async () => { + const wrapper = mount(Stepper, { + propsData: { + value: 1.33 + } + }); + + wrapper.setProps({ + decimalLength: 1 + }); + + await later(); + + expect(wrapper.emitted('input')[0][0]).toEqual('1.3'); +}); + +test('change integer', async () => { + const wrapper = mount(Stepper, { + propsData: { + value: 1.33 + } + }); + + wrapper.setProps({ + integer: true + }); + + await later(); + + expect(wrapper.emitted('input')[0][0]).toEqual(1); +});