mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* fix: won't display warning in when placeholder (#2346) * chore: update use-multiselect-list-state.ts * chore: add change log
This commit is contained in:
parent
e83595e06f
commit
d8b0ef528b
5
.changeset/chilled-cups-tell.md
Normal file
5
.changeset/chilled-cups-tell.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@nextui-org/use-aria-multiselect": patch
|
||||
---
|
||||
|
||||
fix won't display warning when placeholder (#2346)
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user