-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathComboBoxExample4.razor
More file actions
63 lines (57 loc) · 2.59 KB
/
ComboBoxExample4.razor
File metadata and controls
63 lines (57 loc) · 2.59 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 justify-center">
<MudComboBox @bind-Value="@_value" @bind-SelectedValues="@_selectedValues" Variant="Variant.Filled" Label="Gryffindor" MultiSelection="true" Editable="_editable"
SelectAll="_selectAll" ShowCheckbox="_showCheckbox" Bordered="_bordered" Dense="_dense"
autocomplete="new-password" Color="_color" Clearable="_clearable">
<ChildContent>
@foreach (var item in characters)
{
<MudComboBoxItem Value="@item" Text="@item"></MudComboBoxItem>
}
</ChildContent>
<PopoverEndContent>
<div class="d-flex gap-4 pa-4">
<MudIconButton Icon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" Color="_color" OnClick="AddItem" />
<MudTextFieldExtended @bind-Value="_toBeAddedValue" Variant="Variant.Outlined" Margin="Margin.Dense" />
</div>
</PopoverEndContent>
</MudComboBox>
</MudItem>
<MudItem xs="12" sm="4">
<MudStack Spacing="4">
<MudSwitchM3 @bind-Value="@_editable" Label="Editable" Color="Color.Secondary" />
<MudSwitchM3 @bind-Value="@_selectAll" Label="Select All" Color="Color.Secondary" />
<MudSwitchM3 @bind-Value="@_showCheckbox" Label="Show Checkbox" Color="Color.Secondary" />
<MudSwitchM3 @bind-Value="@_bordered" Label="Bordered" Color="Color.Secondary" />
<MudSwitchM3 @bind-Value="@_clearable" Label="Clearable" Color="Color.Secondary" />
<MudSelectExtended @bind-Value="_dense" ItemCollection="@(Enum.GetValues<Dense>())" Label="Dense" Variant="Variant.Outlined" />
<MudSelectExtended @bind-Value="_color" ItemCollection="@(Enum.GetValues<Color>())" Label="Color" Variant="Variant.Outlined" />
</MudStack>
</MudItem>
</MudGrid>
@code {
string? _value;
IEnumerable<string>? _selectedValues;
Dense _dense = Dense.Standard;
Color _color = Color.Primary;
bool _selectAll;
bool _bordered;
bool _showCheckbox = true;
bool _editable;
bool _clearable;
string? _toBeAddedValue;
private List<string> characters = new()
{
"Harry Potter", "Ron Weasley", "Hermione Granger", "Seamus Finnigan", "Oliver Wood"
};
private void AddItem()
{
if (string.IsNullOrEmpty(_toBeAddedValue))
{
return;
}
characters.Add(_toBeAddedValue);
_toBeAddedValue = null;
}
}