Skip to content

Commit 851826d

Browse files
authored
fix(form): ProSelect 开启 showSearch 默认情况会同时匹配 label 和 value (#9162)
* fix(Select): 在渲染函数中添加options参数以增强功能 * feature: TreeSelect render模式下也增加 options * fix: TreeSelect render 模式下增加treeData * fix: proselect filterOption 未使用optionFilterProp配置,会同时匹配 label 和 value 的值,不合理
1 parent a9c1cc5 commit 851826d

File tree

1 file changed

+15
-12
lines changed
  • packages/field/src/components/Select/SearchSelect

1 file changed

+15
-12
lines changed

packages/field/src/components/Select/SearchSelect/index.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,18 @@ const SearchSelect = <T,>(props: SearchSelectProps<T[]>, ref: any) => {
163163
const getMergeValue: SelectProps<any>['onChange'] = (value, option) => {
164164
if (Array.isArray(value) && Array.isArray(option) && value.length > 0) {
165165
// 多选情况且用户有选择
166+
166167
return value.map((item, index) => {
167168
const optionItem = (option as DefaultOptionType[])?.[
168169
index
169170
] as DefaultOptionType;
170-
const dataItem = optionItem?.['data-item'] || {};
171+
const dataItem = optionItem?.['data-item'];
172+
171173
return {
172-
...dataItem,
174+
...(dataItem || {}),
173175
...item,
174-
label: preserveOriginalLabel ? dataItem.label : item.label,
176+
label:
177+
preserveOriginalLabel && dataItem ? dataItem.label : item.label,
175178
};
176179
});
177180
}
@@ -253,11 +256,7 @@ const SearchSelect = <T,>(props: SearchSelectProps<T[]>, ref: any) => {
253256
?.toString()
254257
.toLowerCase()
255258
.includes(inputValue.toLowerCase()) ||
256-
option?.label
257-
?.toString()
258-
.toLowerCase()
259-
.includes(inputValue.toLowerCase()) ||
260-
option?.value
259+
option?.[optionFilterProp]
261260
?.toString()
262261
.toLowerCase()
263262
.includes(inputValue.toLowerCase())
@@ -297,9 +296,10 @@ const SearchSelect = <T,>(props: SearchSelectProps<T[]>, ref: any) => {
297296
? {
298297
...value,
299298
// 这里有一种情况,如果用户使用了 request和labelInValue,保存之后,刷新页面,正常回显,但是再次添加会出现 label 丢失的情况。所以需要兼容
300-
label: preserveOriginalLabel
301-
? dataItem?.label || value.label
302-
: value.label,
299+
label:
300+
preserveOriginalLabel && dataItem
301+
? dataItem?.label || value.label
302+
: value.label,
303303
}
304304
: value;
305305
onChange?.(changedValue, optionList, ...rest);
@@ -308,7 +308,10 @@ const SearchSelect = <T,>(props: SearchSelectProps<T[]>, ref: any) => {
308308
{
309309
...value,
310310
...dataItem,
311-
label: preserveOriginalLabel ? dataItem.label : value.label,
311+
label:
312+
preserveOriginalLabel && dataItem
313+
? dataItem.label
314+
: value.label,
312315
},
313316
optionList,
314317
...rest,

0 commit comments

Comments
 (0)