Compare commits

...

3 Commits

Author SHA1 Message Date
Junior Garcia bfbf74ef6a chore(changeset): changeset 2024-02-16 10:26:45 -03:00
sudongyuer a2767d3bb6 chore: update use-multiselect-list-state.ts 2024-02-14 12:53:15 +08:00
sudongyuer 20acb65b3c fix: won't display warning in when placeholder (#2346) 2024-02-13 23:42:18 +08:00
2 changed files with 16 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@nextui-org/use-aria-multiselect": patch
---
Fixing the keys on multi selection hook
@@ -1,6 +1,6 @@
import {ListState, useListState} from "@react-stately/list";
import {CollectionBase, MultipleSelection, Node} from "@react-types/shared";
import {Key} from "react";
import {Key, useMemo} from "react";
export interface MultiSelectListProps<T> extends CollectionBase<T>, MultipleSelection {}
@@ -25,19 +25,21 @@ export function useMultiSelectListState<T extends object>(
selectionManager: {setSelectedKeys, selectedKeys, selectionMode},
} = useListState<T>(props);
const missingKeys: Key[] = [];
const missingKeys: Key[] = useMemo(() => {
if (selectedKeys.size !== 0) {
return Array.from(selectedKeys)
.filter(Boolean)
.filter((key) => !collection.getItem(key));
}
return [];
}, [selectedKeys, collection]);
const selectedItems = (
selectedKeys.size !== 0
? Array.from(selectedKeys)
.map((key) => {
const item = collection.getItem(key);
if (!item) {
missingKeys.push(key);
}
return item;
return collection.getItem(key);
})
// Remove undefined values when some keys are not present in the collection
.filter(Boolean)