-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathSelectExtendedExample6.razor
More file actions
63 lines (55 loc) · 3.17 KB
/
SelectExtendedExample6.razor
File metadata and controls
63 lines (55 loc) · 3.17 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
@namespace MudExtensions.Docs.Examples
<MudGrid>
<MudItem xs="12" sm="8" Class="d-flex gap-4">
<MudSelectExtended @bind-Value="@_selectedState" MultiSelection="@_multiselection" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" Label="Standard (RenderFragment)" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" HelperText="Search with 'Contains' logic" SearchBoxClearable="_searchBoxClearable">
@foreach (var state in _states)
{
<MudSelectItemExtended Value="@state" Text="@state">@state</MudSelectItemExtended>
}
</MudSelectExtended>
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" T="string" Label="Standard (ItemCollection)" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" HelperText="Search with 'Contains' logic" SearchBoxClearable="_searchBoxClearable" />
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" SearchFunc="@(new Func<string, string, bool>(SearchItems))" T="string" Label="Custom Search Func" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" SearchBoxPlaceholder="Some Placeholder" HelperText="Search with 'StartsWith' logic" SearchBoxClearable="_searchBoxClearable" />
</MudItem>
<MudItem xs="12" sm="4">
<MudStack>
<MudSwitchM3 @bind-Value="_multiselection" Color="Color.Primary" Label="MultiSelection" />
<MudSwitchM3 @bind-Value="_searchBoxAutoFocus" Color="Color.Primary" Label="AutoFocus (SearchBox)" />
<MudSwitchM3 @bind-Value="_searchBoxClearable" Color="Color.Primary" Label="Clearable (SearchBox)" />
</MudStack>
</MudItem>
</MudGrid>
@code {
bool _multiselection;
bool _searchBoxAutoFocus;
bool _searchBoxClearable;
private string? _selectedState;
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 bool SearchItems(string value, string searchString)
{
if (searchString == "")
{
return true;
}
if (value.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase))
{
return true;
}
return false;
}
}