Skip to content

Commit 5953ba6

Browse files
authored
chore: findValueOption add props info (#644)
* chore: Patch props info of findValueOption * chore: Patch props info of findValueOption * fix: TS
1 parent d94c7c1 commit 5953ba6

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/generate.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
209209
| ((
210210
values: RawValueType[],
211211
options: FlattenOptionsType<OptionsType>,
212-
info?: { prevValueOptions?: OptionsType[] },
212+
info?: { prevValueOptions?: OptionsType[]; props?: any },
213213
) => OptionsType);
214214
/** Check if a value is disabled */
215215
isValueDisabled: (value: RawValueType, options: FlattenOptionsType<OptionsType>) => boolean;
@@ -233,7 +233,7 @@ export default function generateSelector<
233233
label?: React.ReactNode;
234234
key?: Key;
235235
disabled?: boolean;
236-
}[]
236+
}[],
237237
>(config: GenerateConfig<OptionsType>) {
238238
const {
239239
prefixCls: defaultPrefixCls,
@@ -527,18 +527,20 @@ export default function generateSelector<
527527

528528
const triggerSelect = (newValue: RawValueType, isSelect: boolean, source: SelectSource) => {
529529
const newValueOption = getValueOption([newValue]);
530-
const outOption = findValueOption([newValue], newValueOption)[0];
530+
const outOption = findValueOption([newValue], newValueOption, { props })[0];
531531

532532
if (!internalProps.skipTriggerSelect) {
533533
// Skip trigger `onSelect` or `onDeselect` if configured
534-
const selectValue = (mergedLabelInValue
535-
? getLabeledValue(newValue, {
536-
options: newValueOption,
537-
prevValueMap: mergedValueMap,
538-
labelInValue: mergedLabelInValue,
539-
optionLabelProp: mergedOptionLabelProp,
540-
})
541-
: newValue) as SingleType<ValueType>;
534+
const selectValue = (
535+
mergedLabelInValue
536+
? getLabeledValue(newValue, {
537+
options: newValueOption,
538+
prevValueMap: mergedValueMap,
539+
labelInValue: mergedLabelInValue,
540+
optionLabelProp: mergedOptionLabelProp,
541+
})
542+
: newValue
543+
) as SingleType<ValueType>;
542544

543545
if (isSelect && onSelect) {
544546
onSelect(selectValue, outOption);
@@ -576,7 +578,10 @@ export default function generateSelector<
576578
const outValue: ValueType = (isMultiple ? outValues : outValues[0]) as ValueType;
577579
// Skip trigger if prev & current value is both empty
578580
if (onChange && (mergedRawValue.length !== 0 || outValues.length !== 0)) {
579-
const outOptions = findValueOption(newRawValues, newRawValuesOptions, { prevValueOptions });
581+
const outOptions = findValueOption(newRawValues, newRawValuesOptions, {
582+
prevValueOptions,
583+
props,
584+
});
580585

581586
// We will cache option in case it removed by ajax
582587
setPrevValueOptions(
@@ -756,9 +761,7 @@ export default function generateSelector<
756761
if (!searchText || !searchText.trim()) {
757762
return;
758763
}
759-
const newRawValues = Array.from(
760-
new Set<RawValueType>([...mergedRawValue, searchText]),
761-
);
764+
const newRawValues = Array.from(new Set<RawValueType>([...mergedRawValue, searchText]));
762765
triggerChange(newRawValues);
763766
newRawValues.forEach((newRawValue) => {
764767
triggerSelect(newRawValue, true, 'input');
@@ -1148,7 +1151,7 @@ export default function generateSelector<
11481151

11491152
// Ref of Select
11501153
type RefSelectFuncType = typeof RefSelectFunc;
1151-
const RefSelect = ((React.forwardRef as unknown) as RefSelectFuncType)(Select);
1154+
const RefSelect = (React.forwardRef as unknown as RefSelectFuncType)(Select);
11521155

11531156
return RefSelect;
11541157
}

0 commit comments

Comments
 (0)