Skip to content

Commit

Permalink
fix: select label-in-value error #3216
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Nov 19, 2020
1 parent 00455da commit 994e709
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions components/vc-select/utils/valueUtil.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -151,7 +151,13 @@ export const getLabeledValue: GetLabeledValue<FlattenOptionData[]> = (
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;
}
Expand Down
2 changes: 1 addition & 1 deletion components/vc-select/utils/warningPropsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 994e709

Please sign in to comment.