Skip to content

Commit e38e59d

Browse files
committed
fix: multipe select can not separator content, #4844
1 parent 80f9b9e commit e38e59d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

components/_util/props-util/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ function isValidElement(element) {
396396
function getPropsSlot(slots, props, prop = 'default') {
397397
return props[prop] ?? slots[prop]?.();
398398
}
399+
400+
export const getTextFromElement = ele => {
401+
if (isValidElement(ele) && isStringElement(ele[0])) {
402+
return ele[0].children;
403+
}
404+
return ele;
405+
};
399406
export {
400407
splitAttrs,
401408
hasProp,

components/select/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Select component to select value from options.
4545
| mode | Set mode of Select | 'multiple' \| 'tags' | - | |
4646
| notFoundContent | Specify content to show when no result matches.. | string\|slot | 'Not Found' | |
4747
| optionFilterProp | Which prop value of option will be used for filter if filterOption is true | string | value | |
48-
| optionLabelProp | Which prop value of option will render as content of select. | string | `value` for `combobox`, `children` for other modes | |
48+
| optionLabelProp | Which prop value of option will render as content of select. | string | `children` \| `label`(when use options) | |
4949
| placeholder | Placeholder of select | string\|slot | - | |
5050
| showSearch | Whether show search input in single mode. | boolean | false | |
5151
| showArrow | Whether to show the drop-down arrow | boolean | true | |

components/select/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/_0XzgOis7/Select.svg
4646
| mode | 设置 Select 的模式为多选或标签 | 'multiple' \| 'tags' \| 'combobox' | - | |
4747
| notFoundContent | 当下拉列表为空时显示的内容 | string\|slot | 'Not Found' | |
4848
| optionFilterProp | 搜索时过滤对应的 option 属性,不支持 children | string | value | |
49-
| optionLabelProp | 回填到选择框的 Option 的属性值,默认是 Option 的子元素。比如在子元素需要高亮效果时,此值可以设为 `value`| string | `children` (combobox 模式下为 `value` | |
49+
| optionLabelProp | 回填到选择框的 Option 的属性值,默认是 Option 的子元素。比如在子元素需要高亮效果时,此值可以设为 `value`| string | `children` \| `label`(设置 options 时) | |
5050
| placeholder | 选择框默认文字 | string\|slot | - | |
5151
| showSearch | 使单选模式可搜索 | boolean | false | |
5252
| showArrow | 是否显示下拉小箭头 | boolean | true | |

components/vc-select/generate.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import createRef from '../_util/createRef';
5353
import PropTypes from '../_util/vue-types';
5454
import warning from '../_util/warning';
5555
import isMobile from '../vc-util/isMobile';
56+
import { getTextFromElement } from '../_util/props-util';
5657

5758
const DEFAULT_OMIT_PROPS = [
5859
'children',
@@ -699,7 +700,7 @@ export default function generateSelector<
699700
patchRawValues = patchLabels
700701
.map(label => {
701702
const item = mergedFlattenOptions.value.find(
702-
({ data }) => data[mergedOptionLabelProp.value] === label,
703+
({ data }) => getTextFromElement(data[mergedOptionLabelProp.value]) === label,
703704
);
704705
return item ? item.data.value : null;
705706
})

0 commit comments

Comments
 (0)