fix(components): [el-select-v2] use :model-value without changes (#20149)

fix(components): [el-select-v2] model-value bug
This commit is contained in:
Egor Rakutov 2025-03-18 11:33:19 +03:00 committed by GitHub
parent e9d82e59e9
commit a3e774e12c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View File

@ -1488,6 +1488,35 @@ describe('Select', () => {
expect(wrapper.findAll('.el-tag').length).toBe(2)
})
it('tag list should be empty when model-value is empty', async () => {
const wrapper = _mount(
`<el-select
model-value=""
:options="[
{
value: 1,
label: 1,
},
]"
multiple
/>`
)
await wrapper.find(`.${WRAPPER_CLASS_NAME}`).trigger('click')
const option = document.querySelector(`.${OPTION_ITEM_CLASS_NAME}`)
option.click()
await nextTick()
option.click()
await nextTick()
option.click()
await nextTick()
await nextTick()
expect(wrapper.findAll('.el-tag').length).toBe(0)
})
it('should reset placeholder after clear when both multiple and filterable are true', async () => {
const wrapper = createSelect({
data() {

View File

@ -548,6 +548,14 @@ const useSelect = (props: ISelectV2Props, emit: SelectEmitFn) => {
selectedOptions = [...selectedOptions, getValue(option)]
states.cachedOptions.push(option)
selectNewOption(option)
nextTick(() => {
const isModelChanged = isEqual(selectedOptions, props.modelValue)
if (!isModelChanged) {
states.cachedOptions.pop()
}
})
}
update(selectedOptions)
if (option.created) {