Skip to content

Commit 994e709

Browse files
committed
fix: select label-in-value error #3216
1 parent 00455da commit 994e709

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

components/vc-select/utils/valueUtil.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { warning } from '../../vc-util/warning';
2-
import { isVNode, VNodeChild } from 'vue';
2+
import { cloneVNode, isVNode, VNodeChild } from 'vue';
33
import {
44
OptionsType as SelectOptionsType,
55
OptionData,
@@ -151,7 +151,13 @@ export const getLabeledValue: GetLabeledValue<FlattenOptionData[]> = (
151151
warning(false, '`label` of `value` is not same as `label` in Select options.');
152152
}
153153
} else if (item && optionLabelProp in item) {
154-
result.label = item[optionLabelProp];
154+
if (Array.isArray(item[optionLabelProp])) {
155+
result.label = isVNode(item[optionLabelProp][0])
156+
? cloneVNode(item[optionLabelProp][0])
157+
: item[optionLabelProp];
158+
} else {
159+
result.label = item[optionLabelProp];
160+
}
155161
} else {
156162
result.label = value;
157163
}

components/vc-select/utils/warningPropsUtil.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function warningProps(props: SelectProps) {
8989
warning(
9090
!labelInValue ||
9191
values.every(val => typeof val === 'object' && ('key' in val || 'value' in val)),
92-
'`value` should in shape of `{ value: string | number, label?: ReactNode }` when you set `labelInValue` to `true`',
92+
'`value` should in shape of `{ value: string | number, label?: any }` when you set `labelInValue` to `true`',
9393
);
9494

9595
warning(

0 commit comments

Comments
 (0)