-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathMudComboBox.razor
More file actions
178 lines (167 loc) · 11.7 KB
/
MudComboBox.razor
File metadata and controls
178 lines (167 loc) · 11.7 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@namespace MudExtensions
@using System.Runtime.InteropServices;
@using MudBlazor.Services
@using MudExtensions.Services
@typeparam T
@inherits MudBaseInputExtended<T>
@inject IKeyInterceptorService KeyInterceptorService
@inject IScrollManagerExtended ScrollManagerExtended
<CascadingValue Name="Standalone" Value="false" IsFixed="true">
<CascadingValue Value="@this" IsFixed="true">
<div class="mud-select-extended" id="@_elementId">
<MudInputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
Error="@Error" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required" ForId="@FieldId">
<InputContent>
@*DataVisualiserStyle="@($"min-height: 1.1876em;{(HasValue(Value) && Editable == true ? "padding-bottom: 0px" : null)}")"*@
<MudInputExtended @ref="_inputReference" T="string" InputType="@(Editable && !MultiSelection ? InputType.Text : InputType.Hidden)"
Class="@InputClassname" Style="@InputStyle" Margin="@Margin" Placeholder="@Placeholder" Label="@Label"
Variant="@Variant" Immediate="true"
TextUpdateSuppression="false"
ShowVisualiser="@((MultiSelection && SelectedValues?.Any() == true) || !Editable)" DataVisualiserStyle="min-height: 1.1876em"
@bind-Value="@_searchString" Typo="@Typo"
Underline="@Underline"
HasAdornmentStart="@((AdornmentStart != null))"
Disabled="@GetDisabledState()" ReadOnly="@GetReadOnlyState()" Error="@Error" ErrorId="@ErrorId"
Clearable="@Clearable" ForceClearable="@(Clearable && HasValue(Value))" OnClearButtonClick="@ClearButtonClickHandlerAsync"
MaxLength="@MaxLength" @attributes="UserAttributes" OnBlur="@HandleOnBlur" ShrinkLabel="@(HasValue(Value) || AdornmentStart != null || _isOpen || ShrinkLabel)">
<AdornmentStart>
@AdornmentStart
</AdornmentStart>
<AdornmentEnd>
@if (AdornmentEnd != null)
{
@AdornmentEnd
}
else
{
<MudIcon Icon="@_currentIcon" Color="@AdornmentColor" Size="@IconSize" @onclick="OnAdornmentClick" />
}
</AdornmentEnd>
<DataVisualiser>
<div style="flex-basis: content; flex-grow: 0">
@if (!HasValue(Value) && !string.IsNullOrWhiteSpace(Placeholder))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary mud-placeholder-extended">@Placeholder</MudText>
}
else if (InputPresenter == ValuePresenter.Chip)
{
<MudChipSet T="T" Class="d-flex flex-wrap mud-width-full" AllClosable="@ChipCloseable" OnClose="@ChipClosed">
@{
var collection = Items.Where(x => (MultiSelection ? SelectedValues?.Contains(x.Value) == true : Value?.Equals(x.Value) == true))?.ToList();
if (collection is not null)
{
foreach (var item in CollectionsMarshal.AsSpan(collection))
{
<MudChip Class="@ChipClass" Value="@item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? Converter.Set(item.Value) : item.Text)"
Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation />
}
}
}
</MudChipSet>
}
else if (InputPresenter == ValuePresenter.Text && (!Editable || (MultiSelection && Editable)))
{
<div style="white-space: break-spaces">@_dataVisualiserText</div>
}
else if (InputPresenter == ValuePresenter.ItemContent)
{
if (SelectedValues is null)
{
<MudText Typo="Typo.body1" Class="mud-text-secondary mud-placeholder-extended">@Placeholder</MudText>
}
else if (ItemTemplate is not null)
{
if (Value is not null)
{
@ItemTemplate(Items.FirstOrDefault(x => x.Value?.Equals(Value) == true) ?? new MudComboBoxItem<T>())
}
else if (!string.IsNullOrWhiteSpace(Placeholder))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary mud-placeholder-extended">@Placeholder</MudText>
}
}
else if (Items.FirstOrDefault(x => x?.Value?.Equals(Value) == true)?.ChildContent is not null)
{
if (MultiSelection)
{
foreach (var item in CollectionsMarshal.AsSpan(Items))
{
if (SelectedValues.Contains(item.Value))
{
<MudRender>@item.ChildContent</MudRender>
}
}
}
else
{
<MudRender>@Items.FirstOrDefault(x => x.Value?.Equals(Value) == true)?.ChildContent</MudRender>
}
}
else
{
<MudRender>@GetPresenterText()</MudRender>
}
}
</div>
</DataVisualiser>
<ChildContent>
<div class="@TemplateClass">
@if (!HasValue(Value) && !string.IsNullOrWhiteSpace(Placeholder))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary mud-placeholder-extended">@Placeholder</MudText>
}
</div>
</ChildContent>
</MudInputExtended>
<MudPopover Open="_isOpen" MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" OverflowBehavior="OverflowBehavior.FlipAlways" Class="@PopoverClassname" RelativeWidth="@RelativeWidth">
<CascadingValue Value="@this" IsFixed="true">
<div id="@_popoverId" style="@($"overflow-y: auto; max-height: {MaxHeight}px")">
@PopoverStartContent
@if (MultiSelection)
{
<div Style="position: sticky; top: 0px; background-color: var(--mud-palette-background); z-index: 2" @onkeydown:stopPropagation>
@if (Editable)
{
<div class="pa-2">
<MudTextFieldExtended id="@($"{_elementId}-autocomplete")" @ref="@_searchbox" T="string" @bind-Value="@_searchString" Margin="Margin.Dense"
Variant="Variant.Outlined" Immediate="true" OnKeyDown="@SearchBoxHandleKeyDown" OnKeyUp="@SearchBoxHandleKeyUp"
Clearable="@SearchBoxClearable">
<AdornmentEnd>
<MudIcon Icon="@Icons.Material.Filled.Search" Color="@Color" />
</AdornmentEnd>
</MudTextFieldExtended>
</div>
}
@if (SelectAll)
{
<div class="@($"mud-combobox-item mud-combobox-item-clickable mud-combobox-item-{Dense.ToDescriptionString()} mud-ripple d-flex")" @onclick="SelectAllItems" @onclick:stopPropagation="true">
<MudCheckBox Class="mx-4" Dense
@bind-Value="@_allSelected" @onclick="@SelectAllItems"
IndeterminateIcon="@IndeterminateIcon"
Size="@CheckBoxSize"
Color="@EffectiveCheckBoxCheckedColor"
UnCheckedColor="@EffectiveCheckBoxUnCheckedColor" />
<MudText Typo="GetTypo()" Color="@TextColor">@SelectAllText</MudText>
</div>
<MudDivider />
}
</div>
}
@ChildContent
@if (NoItemsContent is not null && !HasEligibleItems())
{
<div class="pa-2">
@NoItemsContent
</div>
}
@PopoverEndContent
</div>
</CascadingValue>
</MudPopover>
</InputContent>
</MudInputControl>
</div>
</CascadingValue>
</CascadingValue>
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
<MudOverlay Visible="@_isOpen" @onmousedown="@CloseMenu" LockScroll="@LockScroll" />