Fix duplicate items appearing in selected list (again) (#5377)

* Fix duplicate detection in useListSelect
* Prevent double invocation of select handler
This commit is contained in:
WithoutPants 2024-10-15 14:29:29 +11:00 committed by GitHub
parent 32c48443b5
commit 5283eb8ce3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -229,13 +229,13 @@ export function useListSelect<T extends { id: string }>(items: T[]) {
function singleSelect(id: string, selected: boolean) {
setLastClickedId(id);
// prevent duplicates
if (selected && selectedIds.has(id)) {
return;
}
setItemsSelected((prevSelected) => {
if (selected) {
// prevent duplicates
if (prevSelected.some((v) => v.id === id)) {
return prevSelected;
}
const item = items.find((i) => i.id === id);
if (item) {
return [...prevSelected, item];

View File

@ -154,6 +154,7 @@ export const GridCard: React.FC<ICardProps> = (props: ICardProps) => {
if (props.selecting) {
props.onSelectedChanged(!props.selected, shiftKey);
event.preventDefault();
event.stopPropagation();
}
}