From 994e709226b6802a45d239337196882fdad91df5 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 19 Nov 2020 23:03:31 +0800 Subject: [PATCH] fix: select label-in-value error #3216 --- components/vc-select/utils/valueUtil.ts | 10 ++++++++-- components/vc-select/utils/warningPropsUtil.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/vc-select/utils/valueUtil.ts b/components/vc-select/utils/valueUtil.ts index 0e6a3f50c6..ae9f68b406 100644 --- a/components/vc-select/utils/valueUtil.ts +++ b/components/vc-select/utils/valueUtil.ts @@ -1,5 +1,5 @@ import { warning } from '../../vc-util/warning'; -import { isVNode, VNodeChild } from 'vue'; +import { cloneVNode, isVNode, VNodeChild } from 'vue'; import { OptionsType as SelectOptionsType, OptionData, @@ -151,7 +151,13 @@ export const getLabeledValue: GetLabeledValue = ( warning(false, '`label` of `value` is not same as `label` in Select options.'); } } else if (item && optionLabelProp in item) { - result.label = item[optionLabelProp]; + if (Array.isArray(item[optionLabelProp])) { + result.label = isVNode(item[optionLabelProp][0]) + ? cloneVNode(item[optionLabelProp][0]) + : item[optionLabelProp]; + } else { + result.label = item[optionLabelProp]; + } } else { result.label = value; } diff --git a/components/vc-select/utils/warningPropsUtil.ts b/components/vc-select/utils/warningPropsUtil.ts index 835046fca9..3462c89e7b 100644 --- a/components/vc-select/utils/warningPropsUtil.ts +++ b/components/vc-select/utils/warningPropsUtil.ts @@ -89,7 +89,7 @@ function warningProps(props: SelectProps) { warning( !labelInValue || 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(