Skip to content

Commit 3db66b6

Browse files
committed
Merge branch 'fix-auto' into studder
# Conflicts: # src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor # src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs # src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
2 parents 9550496 + 9f92a43 commit 3db66b6

11 files changed

Lines changed: 143 additions & 458 deletions

File tree

src/BootstrapBlazor.Server/Components/Samples/AutoCompletes.razor

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
<DemoBlock Title="@Localizer["Block1Title"]" Introduction="@Localizer["Block1Intro"]" Name="Normal">
99
<section ignore>@Localizer["NormalDescription"]</section>
1010
<div style="width: 200px;">
11-
<AutoComplete Items="@StaticItems" IsSelectAllTextOnFocus="true" Value="@Value"></AutoComplete>
11+
<AutoComplete Value="@_value" Items="@StaticItems" IsSelectAllTextOnFocus="true"></AutoComplete>
1212
</div>
1313
</DemoBlock>
1414

1515
<DemoBlock Title="@Localizer["Block2Title"]" Introduction="@Localizer["Block2Intro"]" Name="LikeMatch">
1616
<section ignore>@Localizer["LikeMatchDescription"]</section>
1717
<div style="width: 200px;">
18-
<AutoComplete Items="@StaticItems" IsLikeMatch="true" IgnoreCase="false" />
18+
<AutoComplete Value="@_matchValue" Items="@StaticItems" IsLikeMatch="true" IgnoreCase="false" />
1919
</div>
2020
</DemoBlock>
2121

2222
<DemoBlock Title="@Localizer["Block3Title"]" Introduction="@Localizer["Block3Intro"]" Name="NoDataTip">
2323
<section ignore>@((MarkupString)Localizer["NoDataTipDescription"].Value)</section>
2424
<div style="width: 200px;">
25-
<AutoComplete Items="@StaticItems" NoDataTip="@Localizer["NoDataTip"]" />
25+
<AutoComplete Value="@_tipValue" Items="@StaticItems" NoDataTip="@Localizer["NoDataTip"]" />
2626
</div>
2727
</DemoBlock>
2828

29-
<DemoBlock Title="@Localizer["Block4Title"]" Introduction="@Localizer["Block4Intro"]" Name="ValueChanged">
29+
<DemoBlock Title="@Localizer["Block4Title"]" Introduction="@Localizer["Block4Intro"]" Name="OnCustomFilter">
3030
<section ignore>@Localizer["ValueChangedDescription"]</section>
3131
<div style="width: 200px;">
32-
<AutoComplete Items="@Items" ValueChanged="@OnValueChanged" />
32+
<AutoComplete Value="@_filterValue" Items="@Items" OnCustomFilter="OnCustomFilter" />
3333
</div>
3434
</DemoBlock>
3535

@@ -48,12 +48,12 @@
4848
<DemoBlock Title="@Localizer["DebounceTitle"]" Introduction="@Localizer["DebounceIntro"]" Name="Debounce">
4949
<section ignore>@Localizer["DebounceDescription"]</section>
5050
<div style="width: 200px;">
51-
<AutoComplete Items="@Items" ValueChanged="@OnValueChanged" Debounce="500" />
51+
<AutoComplete @bind-Value="@_debounceValue" Items="@Items" Debounce="500" />
5252
</div>
5353
</DemoBlock>
5454

5555
<DemoBlock Title="@Localizer["OnSelectedItemChangedTitle"]" Introduction="@Localizer["OnSelectedItemChangedIntro"]" Name="OnSelectedItemChanged">
56-
<AutoComplete Items="@StaticItems" OnSelectedItemChanged="OnSelectedItemChanged" Debounce="500"></AutoComplete>
56+
<AutoComplete Items="@StaticItems" OnSelectedItemChanged="OnSelectedItemChanged"></AutoComplete>
5757
<section ignore>
5858
<ConsoleLogger @ref="Logger" />
5959
</section>

src/BootstrapBlazor.Server/Components/Samples/AutoCompletes.razor.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ public sealed partial class AutoCompletes
1818

1919
private IEnumerable<string> Items => _items;
2020

21-
private string Value { get; set; } = "";
21+
private string _value = "";
22+
private string _matchValue = "";
23+
private string _tipValue = "";
24+
private string _filterValue = "";
25+
private string _debounceValue = "";
2226

23-
private Task OnValueChanged(string val)
27+
private static async Task<IEnumerable<string>> OnCustomFilter(string val)
2428
{
25-
_items.Clear();
26-
_items.Add($"{val}@163.com");
27-
_items.Add($"{val}@126.com");
28-
_items.Add($"{val}@sina.com");
29-
_items.Add($"{val}@hotmail.com");
30-
return Task.CompletedTask;
29+
await Task.Yield();
30+
var items = new List<string> { $"{val}@163.com", $"{val}@126.com", $"{val}@sina.com", $"{val}@hotmail.com" };
31+
return items;
3132
}
3233

3334
[NotNull]

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66
<BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText"/>
77
}
88
<div class="auto-complete" id="@Id">
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-
*@
169
<input @attributes="AdditionalAttributes" id="@InputId" class="@ClassName" autocomplete="off" type="text"
1710
data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString"
1811
data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"
1912
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
2013
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString"
2114
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" data-bb-trigger-delete="true"
15+
@bind="@CurrentValueAsString"
2216
placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/>
2317
<span class="form-select-append"><i class="@Icon"></i></span>
2418
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
@@ -28,7 +22,6 @@
2822
</div>
2923

3024
@code {
31-
// Original code block for RenderDropdown remains unchanged
3225
RenderFragment RenderDropdown =>
3326
@<div class="dropdown-menu">
3427
<div class="dropdown-menu-body">

0 commit comments

Comments
 (0)