Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
| ((
values: RawValueType[],
options: FlattenOptionsType<OptionsType>,
info?: { prevValueOptions?: OptionsType[] },
info?: { prevValueOptions?: OptionsType[]; props?: any },
) => OptionsType);
/** Check if a value is disabled */
isValueDisabled: (value: RawValueType, options: FlattenOptionsType<OptionsType>) => boolean;
Expand All @@ -233,7 +233,7 @@ export default function generateSelector<
label?: React.ReactNode;
key?: Key;
disabled?: boolean;
}[]
}[],
>(config: GenerateConfig<OptionsType>) {
const {
prefixCls: defaultPrefixCls,
Expand Down Expand Up @@ -527,18 +527,20 @@ export default function generateSelector<

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

if (!internalProps.skipTriggerSelect) {
// Skip trigger `onSelect` or `onDeselect` if configured
const selectValue = (mergedLabelInValue
? getLabeledValue(newValue, {
options: newValueOption,
prevValueMap: mergedValueMap,
labelInValue: mergedLabelInValue,
optionLabelProp: mergedOptionLabelProp,
})
: newValue) as SingleType<ValueType>;
const selectValue = (
mergedLabelInValue
? getLabeledValue(newValue, {
options: newValueOption,
prevValueMap: mergedValueMap,
labelInValue: mergedLabelInValue,
optionLabelProp: mergedOptionLabelProp,
})
: newValue
) as SingleType<ValueType>;

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

// We will cache option in case it removed by ajax
setPrevValueOptions(
Expand Down Expand Up @@ -756,9 +761,7 @@ export default function generateSelector<
if (!searchText || !searchText.trim()) {
return;
}
const newRawValues = Array.from(
new Set<RawValueType>([...mergedRawValue, searchText]),
);
const newRawValues = Array.from(new Set<RawValueType>([...mergedRawValue, searchText]));
triggerChange(newRawValues);
newRawValues.forEach((newRawValue) => {
triggerSelect(newRawValue, true, 'input');
Expand Down Expand Up @@ -1148,7 +1151,7 @@ export default function generateSelector<

// Ref of Select
type RefSelectFuncType = typeof RefSelectFunc;
const RefSelect = ((React.forwardRef as unknown) as RefSelectFuncType)(Select);
const RefSelect = (React.forwardRef as unknown as RefSelectFuncType)(Select);

return RefSelect;
}