From c2afbaf337dc933aa3858187e0010255ee2b82d5 Mon Sep 17 00:00:00 2001 From: zhouyun1 Date: Tue, 28 May 2024 11:08:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(table):=20=E4=BF=AE=E5=A4=8D=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E8=AE=BE=E7=BD=AE=20fieldKey=20=E5=92=8C=20rowSelecti?= =?UTF-8?q?on=20=E6=97=B6=20onChange=20=E5=9B=9E=E8=B0=83=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98=20(#2836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/nervous-scissors-care.md | 5 +++++ .changeset/purple-laws-check.md | 5 +++++ packages/ui/table/src/hooks/use-check.ts | 14 +++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .changeset/nervous-scissors-care.md create mode 100644 .changeset/purple-laws-check.md diff --git a/.changeset/nervous-scissors-care.md b/.changeset/nervous-scissors-care.md new file mode 100644 index 000000000..19fa73b9c --- /dev/null +++ b/.changeset/nervous-scissors-care.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +fix(table): 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题 diff --git a/.changeset/purple-laws-check.md b/.changeset/purple-laws-check.md new file mode 100644 index 000000000..79ac581cf --- /dev/null +++ b/.changeset/purple-laws-check.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/table": patch +--- + +fix: 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题 diff --git a/packages/ui/table/src/hooks/use-check.ts b/packages/ui/table/src/hooks/use-check.ts index 97634cd7f..6bc18d143 100644 --- a/packages/ui/table/src/hooks/use-check.ts +++ b/packages/ui/table/src/hooks/use-check.ts @@ -31,10 +31,10 @@ export const useTableCheck = ({ ) useEffect(() => { - checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(({ key }) => - checkedRowKeys?.includes(key) + checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter((item) => + checkedRowKeys?.includes(item[fieldKey]) ) - }, [checkedRowKeys]) + }, [checkedRowKeys, fieldKey]) // 已选中的行数据集合 const checkedRowDataItemsRef = React.useRef[]>([]) @@ -53,8 +53,8 @@ export const useTableCheck = ({ const onCheckedRowKeysChange = React.useCallback( (rowItem: Record, checked: boolean) => { // 记录选中的行数据集合 - const nextCheckedDataItems = checkedRowDataItems.filter(({ key }) => - checkedRowKeys.includes(key) + const nextCheckedDataItems = checkedRowDataItems.filter((item) => + checkedRowKeys.includes(item[fieldKey]) ) if (checked) { @@ -110,7 +110,7 @@ export const useTableCheck = ({ if (checkedAll) { checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter( - ({ key }) => !checkedRowKeysSet.has(key) + (item) => !checkedRowKeysSet.has(item[fieldKey]) ) // 移除当前页所有行 ids @@ -125,7 +125,7 @@ export const useTableCheck = ({ } checkedRowDataItemsRef.current = targetRowItems.concat( - checkedRowDataItemsRef.current.filter((item) => !checkedRowKeysSet.has(item.key)) + checkedRowDataItemsRef.current.filter((item) => !checkedRowKeysSet.has(item[fieldKey])) ) trySetCheckedRowKeys(