Skip to content

Commit

Permalink
fix: select onchange params (#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn authored Dec 31, 2024
1 parent 1a4d630 commit 0768c12
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/select/base/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,22 @@ const Select = forwardRefWithStatics(
.filter((option) => !option.checkAll && !option.disabled)
.map((option) => (valueType === 'object' ? option : option[keys?.value || 'value']));

const { currentSelectedOptions } = getSelectedOptions(values, multiple, valueType, keys, tmpPropOptions);
const { currentSelectedOptions, allSelectedValue } = getSelectedOptions(
values,
multiple,
valueType,
keys,
tmpPropOptions,
);

const checkAllValue =
!checkAll && currentSelectedOptions.length !== (props.value as Array<SelectOption>)?.length
? currentSelectedOptions
: [];
!checkAll && allSelectedValue.length !== (props.value as Array<SelectOption>)?.length ? allSelectedValue : [];

onChange?.(checkAllValue, { e, trigger: checkAll ? 'check' : 'uncheck', selectedOptions: checkAllValue });
onChange?.(checkAllValue, {
e,
trigger: checkAll ? 'check' : 'uncheck',
selectedOptions: currentSelectedOptions,
});
};

// 选中 Popup 某项
Expand Down
14 changes: 10 additions & 4 deletions src/select/util/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,29 @@ export const getSelectedOptions = (
let currentSelectedOptions = [];
// 当前选中的选项
let currentOption: SelectOption;
// 全选值
let allSelectedValue: Array<SelectValue>;
if (multiple) {
currentSelectedOptions = isObjectType
? (value as Array<SelectValue>)
: tmpPropOptions
?.filter?.((v) => (value as Array<string | number>).includes?.(v[keys?.value || 'value']))
.map((v) => v[keys?.value || 'value']);
: tmpPropOptions?.filter?.((v) => (value as Array<string | number>).includes?.(v[keys?.value || 'value']));

allSelectedValue = isObjectType
? currentSelectedOptions
: currentSelectedOptions?.map((v) => v[keys?.value || 'value']);

currentOption = isObjectType
? (value as Array<SelectValue>).find((v) => v[keys?.value || 'value'] === selectedValue)
: currentSelectedOptions?.find((option) => option[keys?.value || 'value'] === selectedValue);
} else {
currentSelectedOptions = isObjectType
? [value]
: tmpPropOptions?.filter?.((v) => value === v[keys?.value || 'value']) || [];
allSelectedValue = currentSelectedOptions;
currentOption = isObjectType
? value
: currentSelectedOptions?.find((option) => option[keys?.value || 'value'] === selectedValue);
}

return { currentSelectedOptions, currentOption };
return { currentSelectedOptions, currentOption, allSelectedValue };
};

0 comments on commit 0768c12

Please sign in to comment.