Skip to content

Commit 03568a6

Browse files
authored
Fix select all when virtualize is enabled (#385)
1 parent cce0617 commit 03568a6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ protected string? SelectAllCheckBoxIcon
12951295
/// <param name="deselect"></param>
12961296
protected void SelectAllItems(bool? deselect = false)
12971297
{
1298+
// Select all the components currently rendered
12981299
var items = CollectAllMudListItems(true);
12991300
if (deselect == true)
13001301
{
@@ -1322,7 +1323,20 @@ protected void SelectAllItems(bool? deselect = false)
13221323
var selectedItems = items.Where(x => x.IsSelected).Select(y => y.Value).ToHashSet(_comparer);
13231324
if (ItemCollection != null)
13241325
{
1325-
SelectedValues = deselect == true ? Enumerable.Empty<T?>() : selectedItems;
1326+
var searchedItems = GetSearchedItems();
1327+
// Without virtualization, we are sure that selectedItems will reflect the correct
1328+
// state after the select/deselect all
1329+
1330+
// With virtualization, we can't make that assumption. selectedItems only contains the
1331+
// rendered items
1332+
if (Virtualize && deselect is null or false && searchedItems != null && searchedItems.Count != selectedItems.Count)
1333+
{
1334+
SelectedValues = searchedItems.ToHashSet(_comparer);
1335+
}
1336+
else
1337+
{
1338+
SelectedValues = deselect == true ? Enumerable.Empty<T?>() : selectedItems;
1339+
}
13261340
}
13271341
else
13281342
{

0 commit comments

Comments
 (0)