From dba6a63e205fdcd2f737c8b5b5f756b6ffbcf90d Mon Sep 17 00:00:00 2001 From: xc <124118265@qq.com> Date: Tue, 15 Mar 2022 19:36:41 +0800 Subject: [PATCH] fix: selet-v2 value-key mode selected style and onClonse bug (#6602) * fix: selet-v2 value-key mode selected style and onClonse bug * style: format Co-authored-by: xiaochenchen --- packages/components/select-v2/src/select-dropdown.vue | 5 +++-- packages/components/select-v2/src/useSelect.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/components/select-v2/src/select-dropdown.vue b/packages/components/select-v2/src/select-dropdown.vue index d4204a43db..7d3fb1e7c0 100644 --- a/packages/components/select-v2/src/select-dropdown.vue +++ b/packages/components/select-v2/src/select-dropdown.vue @@ -82,10 +82,11 @@ export default defineComponent({ } const isItemSelected = (modelValue: any[] | any, target: Option) => { + const { valueKey } = select.props if (select.props.multiple) { - return contains(modelValue, target.value) + return contains(modelValue, get(target, valueKey)) } - return isEqual(modelValue, target.value) + return isEqual(modelValue, get(target, valueKey)) } const isItemDisabled = (modelValue: any[] | any, selected: boolean) => { diff --git a/packages/components/select-v2/src/useSelect.ts b/packages/components/select-v2/src/useSelect.ts index 1df3f126d1..365b95e34c 100644 --- a/packages/components/select-v2/src/useSelect.ts +++ b/packages/components/select-v2/src/useSelect.ts @@ -451,7 +451,8 @@ const useSelect = (props: ExtractPropTypes, emit) => { } const deleteTag = (event: MouseEvent, tag: Option) => { - const index = (props.modelValue as Array).indexOf(tag.value) + const { valueKey } = props + const index = (props.modelValue as Array).indexOf(get(tag, valueKey)) if (index > -1 && !selectDisabled.value) { const value = [ @@ -460,7 +461,7 @@ const useSelect = (props: ExtractPropTypes, emit) => { ] states.cachedOptions.splice(index, 1) update(value) - emit('remove-tag', tag.value) + emit('remove-tag', get(tag, valueKey)) states.softFocus = true removeNewOption(tag) return nextTick(focusAndUpdatePopup)