fix(components): [el-select] (#5952)

This commit is contained in:
JacBiank 2022-02-11 10:28:18 +08:00 committed by GitHub
parent bc7317203b
commit e901c58c63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -1685,4 +1685,30 @@ describe('Select', () => {
).toBe('')
})
})
it('multiple select has an initial value', async () => {
const options = [{ value: `value:Alaska`, label: `label:Alaska` }]
const modelValue = [{ value: `value:Alaska`, label: `label:Alaska` }]
const wrapper = _mount(
`
<el-select v-model="modelValue"
multiple
value-key="value"
filterable>
<el-option
v-for="option in options"
:key="option.value"
:value="option.value"
:label="option.label"
>
</el-option>
</el-select>`,
() => ({
modelValue,
options,
})
)
const select = wrapper.findComponent({ name: 'ElSelect' }).vm
expect(select.selected[0].currentLabel).toBe(options[0].label)
})
})

View File

@ -476,7 +476,11 @@ export const useSelect = (props, states: States, ctx) => {
}
}
if (option) return option
const label = !isObjectValue && !isNull && !isUndefined ? value : ''
const label = isObjectValue
? value.label
: !isNull && !isUndefined
? value
: ''
const newOption = {
value,
currentLabel: label,