mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
fix(components): [select] switching single/multiple generates an error (#18030)
closed #17890
This commit is contained in:
parent
8618a6bcd0
commit
044f0afc1e
@ -2741,4 +2741,14 @@ describe('Select', () => {
|
||||
await wrapper.find(`.${WRAPPER_CLASS_NAME}`).trigger('click')
|
||||
expect(handleClick).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
test('should be run normally when switching multiple', async () => {
|
||||
wrapper = getSelectVm({ multiple: false })
|
||||
const vm = wrapper.vm as any
|
||||
|
||||
await (vm.value = undefined)
|
||||
await (vm.multiple = true)
|
||||
await (vm.multiple = false)
|
||||
expect(vm.value).toBe(undefined)
|
||||
})
|
||||
})
|
||||
|
@ -66,7 +66,7 @@ export const useSelect = (props: ISelectProps, emit) => {
|
||||
cachedOptions: new Map(),
|
||||
disabledOptions: new Map(),
|
||||
optionValues: [] as any[], // sorted value of options
|
||||
selected: props.multiple ? [] : ({} as any),
|
||||
selected: [] as any[],
|
||||
selectionWidth: 0,
|
||||
calculatorWidth: 0,
|
||||
collapseItemWidth: 0,
|
||||
@ -406,7 +406,7 @@ export const useSelect = (props: ISelectProps, emit) => {
|
||||
: props.modelValue
|
||||
const option = getOption(value)
|
||||
states.selectedLabel = option.currentLabel
|
||||
states.selected = option
|
||||
states.selected = [option]
|
||||
return
|
||||
} else {
|
||||
states.selectedLabel = ''
|
||||
@ -456,17 +456,11 @@ export const useSelect = (props: ISelectProps, emit) => {
|
||||
}
|
||||
|
||||
const updateHoveringIndex = () => {
|
||||
if (!props.multiple) {
|
||||
states.hoveringIndex = optionsArray.value.findIndex((item) => {
|
||||
return getValueKey(item) === getValueKey(states.selected)
|
||||
})
|
||||
} else {
|
||||
states.hoveringIndex = optionsArray.value.findIndex((item) =>
|
||||
states.selected.some(
|
||||
(selected) => getValueKey(selected) === getValueKey(item)
|
||||
)
|
||||
states.hoveringIndex = optionsArray.value.findIndex((item) =>
|
||||
states.selected.some(
|
||||
(selected) => getValueKey(selected) === getValueKey(item)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const resetSelectionWidth = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user