|
| 1 | +@namespace BootstrapBlazor.Components |
| 2 | +@using Microsoft.AspNetCore.Components.Web.Virtualization |
| 3 | +@typeparam TValue |
| 4 | +@inherits SelectBase<TValue> |
| 5 | +@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor/Components/Select/Select.razor.js", JSObjectReference = true)] |
| 6 | + |
| 7 | +@if (IsShowLabel) |
| 8 | +{ |
| 9 | + <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" /> |
| 10 | +} |
| 11 | +<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString"> |
| 12 | + <CascadingValue Value="this" IsFixed="true"> |
| 13 | + @Options |
| 14 | + </CascadingValue> |
| 15 | + <RenderTemplate> |
| 16 | + <div class="dropdown-toggle" data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"> |
| 17 | + @if (DisplayTemplate != null) |
| 18 | + { |
| 19 | + <div id="@InputId" class="@InputClassString" tabindex="0"> |
| 20 | + @DisplayTemplate(SelectedRow) |
| 21 | + </div> |
| 22 | + } |
| 23 | + else |
| 24 | + { |
| 25 | + <input type="text" id="@InputId" disabled="@Disabled" placeholder="@PlaceHolder" class="@InputClassString" value="@SelectedRow.Text" @onchange="OnChange" readonly="@ReadonlyString" /> |
| 26 | + } |
| 27 | + <span class="@AppendClassString"><i class="@DropdownIcon"></i></span> |
| 28 | + </div> |
| 29 | + @if (GetClearable()) |
| 30 | + { |
| 31 | + <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span> |
| 32 | + } |
| 33 | + <div class="dropdown-menu"> |
| 34 | + @if (IsVirtualize) |
| 35 | + { |
| 36 | + @if (ShowSearch) |
| 37 | + { |
| 38 | + <div class="@SearchClassString"> |
| 39 | + <input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" @oninput="EventCallback.Factory.CreateBinder<string>(this, async v => await SearchTextChanged(v), SearchText)" aria-label="Search"> |
| 40 | + <i class="@SearchIconString"></i> |
| 41 | + </div> |
| 42 | + } |
| 43 | + <div class="dropdown-virtual"> |
| 44 | + @if (OnQueryAsync == null) |
| 45 | + { |
| 46 | + <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@GetVirtualItems()" ChildContent="RenderRow" /> |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + <Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" ItemsProvider="LoadItems" Placeholder="RenderPlaceHolderRow" ItemContent="RenderRow" @ref="VirtualizeElement" /> |
| 51 | + } |
| 52 | + </div> |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + @if (ShowSearch) |
| 57 | + { |
| 58 | + <div class="@SearchClassString"> |
| 59 | + <input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" @oninput="EventCallback.Factory.CreateBinder<string>(this, async v => await SearchTextChanged(v), SearchText)" aria-label="Search"> |
| 60 | + <i class="@SearchIconString"></i> |
| 61 | + </div> |
| 62 | + } |
| 63 | + @foreach (var itemGroup in Rows.GroupBy(i => i.GroupName)) |
| 64 | + { |
| 65 | + if (!string.IsNullOrEmpty(itemGroup.Key)) |
| 66 | + { |
| 67 | + if (GroupItemTemplate != null) |
| 68 | + { |
| 69 | + @GroupItemTemplate(itemGroup.Key) |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + <Divider Text="@itemGroup.Key" /> |
| 74 | + } |
| 75 | + } |
| 76 | + @foreach (var item in itemGroup) |
| 77 | + { |
| 78 | + @RenderRow(item) |
| 79 | + } |
| 80 | + } |
| 81 | + @if (Rows.Count == 0) |
| 82 | + { |
| 83 | + <div class="dropdown-item">@NoSearchDataText</div> |
| 84 | + } |
| 85 | + } |
| 86 | + </div> |
| 87 | + @if (!IsPopover) |
| 88 | + { |
| 89 | + <div class="dropdown-menu-arrow"></div> |
| 90 | + } |
| 91 | + </RenderTemplate> |
| 92 | +</div> |
| 93 | + |
| 94 | +@code { |
| 95 | + RenderFragment<SelectedItem<TValue>> RenderRow => item => |
| 96 | + @<div class="@ActiveItem(item)" @onclick="() => OnClickItem(item)"> |
| 97 | + @if (ItemTemplate != null) |
| 98 | + { |
| 99 | + @ItemTemplate(item) |
| 100 | + } |
| 101 | + else if (IsMarkupString) |
| 102 | + { |
| 103 | + @((MarkupString)item.Text) |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + @item.Text |
| 108 | + } |
| 109 | + </div>; |
| 110 | + |
| 111 | + RenderFragment<PlaceholderContext> RenderPlaceHolderRow => context => |
| 112 | + @<div class="dropdown-item"> |
| 113 | + <div class="is-ph"></div> |
| 114 | + </div>; |
| 115 | +} |
0 commit comments