From 09ebcb3e4b39cf8336816d61ab5f12525a89f668 Mon Sep 17 00:00:00 2001 From: Uyarn Date: Tue, 31 Dec 2024 11:15:22 +0800 Subject: [PATCH] fix: select onchange params --- src/select/base/Select.tsx | 18 +++++++++++++----- src/select/util/helper.ts | 14 ++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/select/base/Select.tsx b/src/select/base/Select.tsx index e0e3f975b..4f440dff7 100644 --- a/src/select/base/Select.tsx +++ b/src/select/base/Select.tsx @@ -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)?.length - ? currentSelectedOptions - : []; + !checkAll && allSelectedValue.length !== (props.value as Array)?.length ? allSelectedValue : []; - onChange?.(checkAllValue, { e, trigger: checkAll ? 'check' : 'uncheck', selectedOptions: checkAllValue }); + onChange?.(checkAllValue, { + e, + trigger: checkAll ? 'check' : 'uncheck', + selectedOptions: currentSelectedOptions, + }); }; // 选中 Popup 某项 diff --git a/src/select/util/helper.ts b/src/select/util/helper.ts index b69fcda2e..1a0f68973 100644 --- a/src/select/util/helper.ts +++ b/src/select/util/helper.ts @@ -199,12 +199,17 @@ export const getSelectedOptions = ( let currentSelectedOptions = []; // 当前选中的选项 let currentOption: SelectOption; + // 全选值 + let allSelectedValue: Array; if (multiple) { currentSelectedOptions = isObjectType ? (value as Array) - : tmpPropOptions - ?.filter?.((v) => (value as Array).includes?.(v[keys?.value || 'value'])) - .map((v) => v[keys?.value || 'value']); + : tmpPropOptions?.filter?.((v) => (value as Array).includes?.(v[keys?.value || 'value'])); + + allSelectedValue = isObjectType + ? currentSelectedOptions + : currentSelectedOptions?.map((v) => v[keys?.value || 'value']); + currentOption = isObjectType ? (value as Array).find((v) => v[keys?.value || 'value'] === selectedValue) : currentSelectedOptions?.find((option) => option[keys?.value || 'value'] === selectedValue); @@ -212,10 +217,11 @@ export const getSelectedOptions = ( 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 }; };