fix(components): [input-number] modelValue incorrect update (#12007)

This commit is contained in:
Mario34 2023-03-16 00:22:37 +08:00 committed by GitHub
parent 7987f6f73e
commit b5bf0ebf30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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<number>(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<number>()
const wrapper = mount(() => <InputNumber v-model={num.value} />)
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(() => <InputNumber min={3} v-model={num.value} />)

View File

@ -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!)