mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
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:
@@ -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({
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user