diff --git a/polaris-react/src/utilities/use-index-resource-state.ts b/polaris-react/src/utilities/use-index-resource-state.ts index 46a3b651025..014e1e211c5 100644 --- a/polaris-react/src/utilities/use-index-resource-state.ts +++ b/polaris-react/src/utilities/use-index-resource-state.ts @@ -110,20 +110,26 @@ export function useIndexResourceState( return newSelectedResources; }); break; + case SelectionType.All: case SelectionType.Page: { const resourceList = resourceFilter ? resources.filter(resourceFilter) : resources; + const mappedResources = new Set(resourceList.map(resourceIDResolver)); + const hasRoomForMoreSelection = isSelecting && selectedResources.size < resourceList.length; - const resourceIDs = new Set(resourceList.map(resourceIDResolver)); setSelectedResources( - hasRoomForMoreSelection ? resourceIDs : new Set(), + hasRoomForMoreSelection || isSelecting + ? mappedResources + : new Set(), ); setUnselectedResources( - hasRoomForMoreSelection ? new Set() : resourceIDs, + hasRoomForMoreSelection || isSelecting + ? new Set() + : mappedResources, ); break; }