From b5bf0ebf30fd20ade85ff6d8e6d7b5c0a8636777 Mon Sep 17 00:00:00 2001 From: Mario34 Date: Thu, 16 Mar 2023 00:22:37 +0800 Subject: [PATCH] fix(components): [input-number] modelValue incorrect update (#12007) --- .../input-number/__tests__/input-number.test.tsx | 15 +++++++++++++++ .../components/input-number/src/input-number.vue | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/components/input-number/__tests__/input-number.test.tsx b/packages/components/input-number/__tests__/input-number.test.tsx index c984fc3ec7..4b57f95175 100755 --- a/packages/components/input-number/__tests__/input-number.test.tsx +++ b/packages/components/input-number/__tests__/input-number.test.tsx @@ -47,6 +47,7 @@ describe('InputNumber.vue', () => { 'null' ) }) + // fix: #10328 test('Make sure the input action can trigger the modelValue update', async () => { const num = ref(0) @@ -65,6 +66,20 @@ describe('InputNumber.vue', () => { await nextTick() expect(num.value).toEqual(3) }) + + // fix: #11963 + test('Make sure modelValue correct update when no initial value', async () => { + const num = ref() + const wrapper = mount(() => ) + const inputWrapper = wrapper.find('input') + const nativeInput = inputWrapper.element + nativeInput.value = '1' + await inputWrapper.trigger('input') + nativeInput.value = '' + await inputWrapper.trigger('input') + expect(num.value).toEqual(null) + }) + test('min', async () => { const num = ref(1) const wrapper = mount(() => ) diff --git a/packages/components/input-number/src/input-number.vue b/packages/components/input-number/src/input-number.vue index c63a584a62..9febedfb41 100755 --- a/packages/components/input-number/src/input-number.vue +++ b/packages/components/input-number/src/input-number.vue @@ -224,11 +224,11 @@ const setCurrentValue = ( ) => { const oldVal = data.currentValue const newVal = verifyValue(value) - if (oldVal === newVal) return if (!emitChange) { emit(UPDATE_MODEL_EVENT, newVal!) return } + if (oldVal === newVal) return data.userInput = null emit(UPDATE_MODEL_EVENT, newVal!) emit(CHANGE_EVENT, newVal!, oldVal!)