|
1 | | -@* --- File: AutoComplete.razor --- *@ |
2 | | -@namespace BootstrapBlazor.Components |
| 1 | +@namespace BootstrapBlazor.Components |
3 | 2 | @inherits PopoverCompleteBase<string> |
4 | 3 |
|
5 | | -@* Show label if configured *@ |
6 | 4 | @if (IsShowLabel) |
7 | 5 | { |
8 | | - <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" /> |
| 6 | + <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText"/> |
9 | 7 | } |
10 | | - |
11 | | -@* Main container div *@ |
12 | 8 | <div class="auto-complete" id="@Id"> |
13 | | - @* Input element - Value is now controlled primarily by the browser & JS setValue *@ |
14 | | - <input @attributes="AdditionalAttributes" |
15 | | - id="@InputId" |
16 | | - class="@ClassName" |
17 | | - autocomplete="off" |
18 | | - type="text" |
19 | | - data-bs-toggle="@ToggleString" |
20 | | - data-bs-placement="@PlacementString" |
21 | | - data-bs-offset="@OffsetString" |
22 | | - data-bs-custom-class="@CustomClassString" |
23 | | - data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" |
24 | | - data-bb-debounce="@DurationString" |
25 | | - data-bb-skip-esc="@SkipEscString" |
26 | | - data-bb-skip-enter="@SkipEnterString" |
27 | | - data-bb-blur="@TriggerBlurString" |
28 | | - data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" |
29 | | - data-bb-trigger-delete="true" |
30 | | - placeholder="@PlaceHolder" |
31 | | - disabled="@Disabled" |
32 | | - @ref="FocusElement" /> |
33 | | - |
34 | | - @* Icon shown by default *@ |
| 9 | + @* |
| 10 | + INPUT VALUE ATTRIBUTE REMOVED: |
| 11 | + Removed 'value="@CurrentValueAsString"' to prevent Blazor from overwriting |
| 12 | + the user's input during async operations/re-renders (fixes stuttering). |
| 13 | + The input's visual value is now primarily controlled by the browser during typing |
| 14 | + and synchronized via JavaScript interop ('setValue') when needed (init, click, enter, esc). |
| 15 | + *@ |
| 16 | + <input @attributes="AdditionalAttributes" id="@InputId" class="@ClassName" autocomplete="off" type="text" |
| 17 | + data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" |
| 18 | + data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString" |
| 19 | + data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString" |
| 20 | + data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString" |
| 21 | + data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" data-bb-trigger-delete="true" |
| 22 | + placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/> |
35 | 23 | <span class="form-select-append"><i class="@Icon"></i></span> |
36 | | - @* Loading icon shown during filtering *@ |
37 | 24 | <span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span> |
38 | | - |
39 | | - @* Render the dropdown menu using RenderFragment *@ |
40 | 25 | <RenderTemplate @ref="_dropdown"> |
41 | 26 | @RenderDropdown |
42 | 27 | </RenderTemplate> |
43 | 28 | </div> |
44 | 29 |
|
45 | 30 | @code { |
46 | | - // RenderFragment for the dropdown menu content |
| 31 | + // Original code block for RenderDropdown remains unchanged |
47 | 32 | RenderFragment RenderDropdown => |
48 | 33 | @<div class="dropdown-menu"> |
49 | 34 | <div class="dropdown-menu-body"> |
50 | | - @* Iterate through filtered items (Rows) *@ |
51 | 35 | @foreach (var item in Rows) |
52 | | - { |
53 | | - <div @key="item" class="dropdown-item" @onclick="() => OnClickItem(item)"> |
54 | | - @* Use ItemTemplate if provided, otherwise display item directly *@ |
55 | | - @if (ItemTemplate == null) |
56 | 36 | { |
57 | | - <div>@item</div> |
| 37 | + <div @key="item" class="dropdown-item" @onclick="() => OnClickItem(item)"> |
| 38 | + @if (ItemTemplate == null) |
| 39 | + { |
| 40 | + <div>@item</div> |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + @ItemTemplate(item) |
| 45 | + } |
| 46 | + </div> |
58 | 47 | } |
59 | | - else |
| 48 | + @if (ShowNoDataTip && Rows.Count == 0) |
60 | 49 | { |
61 | | - @ItemTemplate(item) |
| 50 | + <div class="dropdown-item">@NoDataTip</div> |
62 | 51 | } |
63 | | - </div> |
64 | | - } |
65 | | - @* Show "No data" tip if configured and no items match *@ |
66 | | - @if (ShowNoDataTip && !Rows.Any()) // Use !Rows.Any() for clarity |
67 | | - { |
68 | | - <div class="dropdown-item disabled">@NoDataTip</div> @* Add 'disabled' class? *@ |
69 | | - } |
70 | 52 | </div> |
71 | 53 | </div>; |
72 | 54 | } |
0 commit comments