Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题 (#2836) #2840

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
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
Loading