From 6775875f96965588b8457801d88f7f27c5907e63 Mon Sep 17 00:00:00 2001 From: Yi Yang Date: Tue, 7 May 2024 21:50:27 +0800 Subject: [PATCH] fix(kselect): avoid incorrect event triggering with null (#2168) --- src/components/KSelect/KSelect.vue | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/KSelect/KSelect.vue b/src/components/KSelect/KSelect.vue index 9d2020b262..4954112e7b 100644 --- a/src/components/KSelect/KSelect.vue +++ b/src/components/KSelect/KSelect.vue @@ -523,6 +523,10 @@ const clearSelection = (): void => { }) selectedItem.value = null filterQuery.value = '' + // this 'input' event must be emitted for v-model binding to work properly + emit('input', null) + emit('change', null) + emit('update:modelValue', null) } const triggerFocus = (evt: any, isToggled: Ref):void => { @@ -655,19 +659,12 @@ watch(filterQuery, (q: string) => { }) watch(selectedItem, (newVal, oldVal) => { - if (newVal) { - if (newVal !== oldVal) { - emit('selected', newVal) - // this 'input' event must be emitted for v-model binding to work properly - emit('input', newVal.value) - emit('change', newVal) - emit('update:modelValue', newVal.value) - } - } else { + if (newVal && newVal !== oldVal) { + emit('selected', newVal) // this 'input' event must be emitted for v-model binding to work properly - emit('input', null) - emit('change', null) - emit('update:modelValue', null) + emit('input', newVal.value) + emit('change', newVal) + emit('update:modelValue', newVal.value) } }, { deep: true })