fix: select label-in-value error #3216
parent
00455da385
commit
994e709226
|
@ -1,5 +1,5 @@
|
||||||
import { warning } from '../../vc-util/warning';
|
import { warning } from '../../vc-util/warning';
|
||||||
import { isVNode, VNodeChild } from 'vue';
|
import { cloneVNode, isVNode, VNodeChild } from 'vue';
|
||||||
import {
|
import {
|
||||||
OptionsType as SelectOptionsType,
|
OptionsType as SelectOptionsType,
|
||||||
OptionData,
|
OptionData,
|
||||||
|
@ -151,7 +151,13 @@ export const getLabeledValue: GetLabeledValue<FlattenOptionData[]> = (
|
||||||
warning(false, '`label` of `value` is not same as `label` in Select options.');
|
warning(false, '`label` of `value` is not same as `label` in Select options.');
|
||||||
}
|
}
|
||||||
} else if (item && optionLabelProp in item) {
|
} else if (item && optionLabelProp in item) {
|
||||||
|
if (Array.isArray(item[optionLabelProp])) {
|
||||||
|
result.label = isVNode(item[optionLabelProp][0])
|
||||||
|
? cloneVNode(item[optionLabelProp][0])
|
||||||
|
: item[optionLabelProp];
|
||||||
|
} else {
|
||||||
result.label = item[optionLabelProp];
|
result.label = item[optionLabelProp];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.label = value;
|
result.label = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ function warningProps(props: SelectProps) {
|
||||||
warning(
|
warning(
|
||||||
!labelInValue ||
|
!labelInValue ||
|
||||||
values.every(val => typeof val === 'object' && ('key' in val || 'value' in val)),
|
values.every(val => typeof val === 'object' && ('key' in val || 'value' in val)),
|
||||||
'`value` should in shape of `{ value: string | number, label?: ReactNode }` when you set `labelInValue` to `true`',
|
'`value` should in shape of `{ value: string | number, label?: any }` when you set `labelInValue` to `true`',
|
||||||
);
|
);
|
||||||
|
|
||||||
warning(
|
warning(
|
||||||
|
|
Loading…
Reference in New Issue