-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathSelectExtendedExample7.razor
More file actions
68 lines (63 loc) · 3.4 KB
/
SelectExtendedExample7.razor
File metadata and controls
68 lines (63 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@namespace MudExtensions.Docs.Examples
<MudGrid>
<MudItem xs="12" sm="8">
<MudSelectExtended ItemCollection="states" SearchBox="true" SelectAllPosition="_selectAllPosition" SelectAll="true" MultiSelectionTextFunc="@GetMultiSelectionText" MultiSelection="true" ValuePresenter="_valuePresenter" @bind-Value="value" @bind-SelectedValues="options" T="string" Label="US States" AdornmentIcon="@Icons.Material.Filled.Search" AnchorOrigin="Origin.BottomCenter">
@foreach (var state in states)
{
<MudSelectItemExtended T="string" Value="@state" Text="@state" />
}
</MudSelectExtended>
</MudItem>
<MudItem xs="12" sm="4">
<MudRadioGroup T="SelectAllPosition" @bind-Value="_selectAllPosition">
<MudRadio Value="SelectAllPosition.BeforeSearchBox" Color="Color.Primary">Before Search (Default)</MudRadio>
<MudRadio Value="SelectAllPosition.NextToSearchBox" Color="Color.Primary">Start of the searchbox in the same line</MudRadio>
<MudRadio Value="SelectAllPosition.AfterSearchBox" Color="Color.Primary">After Search</MudRadio>
</MudRadioGroup>
<MudGrid Class="mt-3 px-4">
<MudItem xs="6">
<MudText Typo="Typo.subtitle2">Value:</MudText>
<MudText Typo="Typo.subtitle2">"</MudText>
<MudText Typo="Typo.body2" Class="pl-4">@value</MudText>
<MudText Typo="Typo.subtitle2">"</MudText>
</MudItem>
<MudItem xs="6">
<MudText Typo="Typo.subtitle2">SelectedValues: HashSet<string></MudText>
<MudText Typo="Typo.subtitle2">{</MudText>
<MudText Typo="Typo.body2" Class="pl-4">@(string.Join(", ", options.Select(x => $"\"{x}\"")))</MudText>
<MudText Typo="Typo.subtitle2">}</MudText>
</MudItem>
</MudGrid>
</MudItem>
</MudGrid>
@code {
ValuePresenter _valuePresenter = ValuePresenter.Text;
SelectAllPosition _selectAllPosition;
string value { get; set; } = "Nothing selected";
IEnumerable<string> options { get; set; } = new HashSet<string>() { "Alaska", "California" };
private string[] states =
{
"Alabama", "Alaska", "American Samoa", "Arizona",
"Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "District of Columbia", "Federated States of Micronesia",
"Florida", "Georgia", "Guam", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
"Louisiana", "Maine", "Marshall Islands", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada",
"New Hampshire", "New Jersey", "New Mexico", "New York",
"North Carolina", "North Dakota", "Northern Mariana Islands", "Ohio",
"Oklahoma", "Oregon", "Palau", "Pennsylvania", "Puerto Rico",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virgin Island", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming",
};
private string? GetMultiSelectionText(List<string> selectedValues)
{
if (!selectedValues.Any())
{
return null;
}
return $"{selectedValues.FirstOrDefault()} + {selectedValues.Count-1} state{(selectedValues.Count-1 > 1 ? "s have" : " has")} been selected";
}
}