Skip to content

Commit

Permalink
docs(components): error in selecting all
Browse files Browse the repository at this point in the history
  • Loading branch information
kuri-sun committed Feb 13, 2024
1 parent d168d23 commit ec8b4d2
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion apps/docs/app/examples/table/use-case/page.tsx
Expand Up @@ -409,10 +409,45 @@ export default function Page() {
setPage(1);
}, []);

const bulkUpdateSelectedKeys = useCallback(
(
updatedSelectedKeys: {
[key: number]: Selection;
},
newSelectedKeys: Selection,
) => {
for (let i = 1; i <= pages; i++) {
updatedSelectedKeys[i] = newSelectedKeys;
}
},
[pages],
);

const isUnselectAllRows = useCallback(
(prevSelectedKeys: Selection, newSelectedKeys: Selection) => {
return (
newSelectedKeys !== "all" &&
newSelectedKeys.size === 0 &&
prevSelectedKeys &&
(prevSelectedKeys === "all" || prevSelectedKeys.size === rowsPerPage)
);
},
[rowsPerPage],
);

const onSelectionChange = (keys: Selection) => {
let updatedSelectedKeys = {...selectedKeys};

updatedSelectedKeys[page] = keys;
if (keys === "all") {
bulkUpdateSelectedKeys(updatedSelectedKeys, "all");
} else {
if (isUnselectAllRows(updatedSelectedKeys[page], keys)) {
bulkUpdateSelectedKeys(updatedSelectedKeys, new Set([]));
} else {
updatedSelectedKeys[page] = keys;
}
}

setSelectedKeys(updatedSelectedKeys);
};

Expand Down

0 comments on commit ec8b4d2

Please sign in to comment.