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 <xiaochen.chen@igg.com>
This commit is contained in:
xc 2022-03-15 19:36:41 +08:00 committed by GitHub
parent bb939c6a58
commit dba6a63e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -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) => {

View File

@ -451,7 +451,8 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, emit) => {
}
const deleteTag = (event: MouseEvent, tag: Option) => {
const index = (props.modelValue as Array<any>).indexOf(tag.value)
const { valueKey } = props
const index = (props.modelValue as Array<any>).indexOf(get(tag, valueKey))
if (index > -1 && !selectDisabled.value) {
const value = [
@ -460,7 +461,7 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, 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)