fix(components): [select-v2] use correct labelKey in selectedLabel (#22516)

* fix(components): [select-v2] use correct labelKey in selectedLabel

* test: add case

* test: update
This commit is contained in:
Zhong
2025-10-18 16:24:17 +08:00
committed by GitHub
parent ff2c26dc89
commit 3508d4f676
2 changed files with 40 additions and 1 deletions

View File

@@ -603,6 +603,45 @@ describe('Select', () => {
})
})
it('should use alias for selected label', async () => {
const wrapper = createSelect({
data: () => {
return {
options: [
{ value: 'value1', name: 'label1', text: 'text1' },
{ value: 'value2', name: 'label2', text: 'text2' },
],
multiple: false,
value: '',
props: { label: 'name' },
}
},
})
await nextTick()
const select = wrapper.findComponent(Select)
const selectVm = select.vm as any
const vm = wrapper.vm as any
const options = getOptions()
options[0].click()
expect(selectVm.selectedLabel).toBe('label1')
vm.value = 'value2'
await nextTick()
expect(selectVm.selectedLabel).toBe('label2')
vm.multiple = true
vm.value = []
await nextTick()
expect(selectVm.selectedLabel).toStrictEqual([])
vm.value = ['value1', 'value2']
await nextTick()
expect(selectVm.selectedLabel).toStrictEqual(['label1', 'label2'])
vm.props.label = 'text'
await nextTick()
expect(selectVm.selectedLabel).toStrictEqual(['text1', 'text2'])
})
describe('multiple', () => {
it('multiple select', async () => {
const wrapper = createSelect({

View File

@@ -366,7 +366,7 @@ export default defineComponent({
if (!props.multiple) {
return API.states.selectedLabel
}
return API.states.cachedOptions.map((i) => i.label as string)
return API.states.cachedOptions.map((i) => API.getLabel(i) as string)
})
return {