fix(components): [select-v2] set modalValue when filtering display error (#15981)

fix(components): [select-v2] set modalValue when filtering

closed #15973
This commit is contained in:
kooriookami 2024-02-29 11:31:26 +08:00 committed by GitHub
parent 9480129c85
commit 3f4bee5a90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -803,6 +803,26 @@ describe('Select', () => {
placeholder = wrapper.find(`.${PLACEHOLDER_CLASS_NAME}`)
expect(placeholder.exists()).toBeTruthy()
})
it('set modelValue when filtering in multiple select', async () => {
const wrapper = createSelect({
data: () => {
return {
multiple: true,
filterable: true,
value: [],
}
},
})
const vm = wrapper.vm as any
const input = wrapper.find('input')
await input.trigger('click')
input.element.value = '1111'
await input.trigger('input')
vm.value = ['option_1']
await nextTick()
expect(wrapper.find('.el-select__tags-text').text()).toBe('a0')
})
})
describe('event', () => {

View File

@ -223,6 +223,15 @@ const useSelect = (props: ISelectV2Props, emit) => {
filteredOptions.value = filterOptions(states.inputValue) as OptionType[]
}
const allOptionsValueMap = computed(() => {
const valueMap = new Map()
allOptions.value.forEach((option, index) => {
valueMap.set(getValueKey(getValue(option)), { option, index })
})
return valueMap
})
const filteredOptionsValueMap = computed(() => {
const valueMap = new Map()
@ -711,8 +720,8 @@ const useSelect = (props: ISelectV2Props, emit) => {
// match the option with the given value, if not found, create a new option
const selectValue = getValueKey(value)
if (filteredOptionsValueMap.value.has(selectValue)) {
const { option } = filteredOptionsValueMap.value.get(selectValue)
if (allOptionsValueMap.value.has(selectValue)) {
const { option } = allOptionsValueMap.value.get(selectValue)
return option
}