Skip to content

Commit

Permalink
fix(table): 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题 (#2836)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed May 28, 2024
1 parent 8c21a52 commit c2afbaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-scissors-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(table): 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题
5 changes: 5 additions & 0 deletions .changeset/purple-laws-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/table": patch
---

fix: 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题
14 changes: 7 additions & 7 deletions packages/ui/table/src/hooks/use-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>[]>([])
Expand All @@ -53,8 +53,8 @@ export const useTableCheck = ({
const onCheckedRowKeysChange = React.useCallback(
(rowItem: Record<string, any>, checked: boolean) => {
// 记录选中的行数据集合
const nextCheckedDataItems = checkedRowDataItems.filter(({ key }) =>
checkedRowKeys.includes(key)
const nextCheckedDataItems = checkedRowDataItems.filter((item) =>
checkedRowKeys.includes(item[fieldKey])
)

if (checked) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const useTableCheck = ({

if (checkedAll) {
checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(
({ key }) => !checkedRowKeysSet.has(key)
(item) => !checkedRowKeysSet.has(item[fieldKey])
)

// 移除当前页所有行 ids
Expand All @@ -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(
Expand Down

0 comments on commit c2afbaf

Please sign in to comment.