Skip to content

Commit ff4d5af

Browse files
authored
Add missing item.SetSelected call for multi select when pre-selection is provided (#240)
* Add missing Set Selected for multi select when pre-selection is provided via a parameter. * Fix selection bug when virtualizing based on an ItemCollection. * add UpdateSelectedStyles on clearing of search text
1 parent c8fd055 commit ff4d5af

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
<MudCheckBox CheckedIcon="@SelectAllCheckBoxIcon" Color="@Color" @bind-Checked="_allSelected" @onclick="() => SelectAllItems(_allSelected)" Dense="true" />
3434
}
35-
<MudTextField @ref="_searchField" @bind-Value="@_searchString" Class="@ClassSearchBox" Placeholder="@SearchBoxPlaceholder" OnKeyDown="SearchBoxHandleKeyDown" OnKeyUp="@(() => UpdateSelectedStyles())" Immediate="true" Variant="Variant.Outlined" Margin="Margin.Dense"
35+
<MudTextField @ref="_searchField" @bind-Value="@_searchString" Class="@ClassSearchBox" Placeholder="@SearchBoxPlaceholder" OnKeyDown="SearchBoxHandleKeyDown" OnKeyUp="@(() => UpdateSelectedStyles())" OnClearButtonClick="@(() => UpdateSelectedStyles())" Immediate="true" Variant="Variant.Outlined" Margin="Margin.Dense"
3636
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color" AutoFocus="@SearchBoxAutoFocus" Clearable="@SearchBoxClearable" />
3737
</div>
3838
</MudListSubheaderExtended>

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ protected void HandleCentralValueCommander(string changedValueType, bool updateS
400400
else if (changedValueType == "MultiSelectionOff")
401401
{
402402
SelectedValue = SelectedValues == null ? default(T) : SelectedValues.FirstOrDefault();
403-
var items = CollectAllMudListItems(true);
404403
SelectedValues = SelectedValue == null ? null : new HashSet<T>(_comparer) { SelectedValue };
405404
UpdateSelectedItem();
406405
}
@@ -762,6 +761,11 @@ protected internal void Register(MudListItemExtended<T> item)
762761
//SelectedItem = item;
763762
//SelectedItemChanged.InvokeAsync(item);
764763
}
764+
765+
if (MultiSelection && SelectedValues != null && SelectedValues.Contains(item.Value))
766+
{
767+
item.SetSelected(true);
768+
}
765769
}
766770

767771
protected internal void Unregister(MudListItemExtended<T> item)
@@ -1068,7 +1072,11 @@ protected internal void UpdateSelectAllState()
10681072
{
10691073
_allSelected = false;
10701074
}
1071-
else if (CollectAllMudListItems(true).Count() == _selectedValues.Count)
1075+
else if (ItemCollection != null && ItemCollection.Count == _selectedValues.Count)
1076+
{
1077+
_allSelected = true;
1078+
}
1079+
else if (ItemCollection == null && CollectAllMudListItems(true).Count() == _selectedValues.Count)
10721080
{
10731081
_allSelected = true;
10741082
}
@@ -1134,7 +1142,15 @@ protected void SelectAllItems(bool? deselect = false)
11341142
_allSelected = true;
11351143
}
11361144

1137-
SelectedValues = items.Where(x => x.IsSelected).Select(y => y.Value).ToHashSet(_comparer);
1145+
if (ItemCollection != null)
1146+
{
1147+
SelectedValues = deselect == true ? Enumerable.Empty<T>() : ItemCollection.ToHashSet(_comparer);
1148+
}
1149+
else
1150+
{
1151+
SelectedValues = items.Where(x => x.IsSelected).Select(y => y.Value).ToHashSet(_comparer);
1152+
}
1153+
11381154
if (MudSelectExtended != null)
11391155
{
11401156
MudSelectExtended.BeginValidatePublic();

0 commit comments

Comments
 (0)