Skip to content

Commit abb3027

Browse files
committed
rollback
undo fix for #5821
1 parent 01178b7 commit abb3027

1 file changed

Lines changed: 27 additions & 88 deletions

File tree

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs

Lines changed: 27 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

6-
using Microsoft.AspNetCore.Components; // Added for Parameter/Inject etc.
76
using Microsoft.Extensions.Localization;
8-
using Microsoft.Extensions.Logging; // Added for ILogger (optional, for handling ex)
9-
using Microsoft.JSInterop; // Added for JSInvokable/IJSRuntime
10-
using System; // Added for Func/StringComparison/Exception
117
using System.Collections.Generic; // Added for List<>
128
using System.Diagnostics.CodeAnalysis; // Added for NotNull
13-
using System.Linq; // Added for Linq methods (Ensure this is present for .Take())
9+
using System.Linq; // Added for Linq methods
10+
using System; // Added for Func/StringComparison/Exception
1411
using System.Threading.Tasks; // Added for Task
12+
using Microsoft.AspNetCore.Components; // Added for Parameter/Inject etc.
13+
using Microsoft.JSInterop; // Added for JSInvokable/IJSRuntime
14+
using Microsoft.Extensions.Logging; // Added for ILogger (optional, for handling ex)
1515

1616
namespace BootstrapBlazor.Components;
1717

@@ -20,6 +20,8 @@ namespace BootstrapBlazor.Components;
2020
/// </summary>
2121
public partial class AutoComplete
2222
{
23+
// Parameters remain the same as original
24+
2325
/// <summary>
2426
/// Gets or sets the collection of matching data obtained by inputting a string
2527
/// </summary>
@@ -76,16 +78,6 @@ public partial class AutoComplete
7678
[Parameter]
7779
public bool ShowNoDataTip { get; set; } = true;
7880

79-
// --- NEW PARAMETER ---
80-
/// <summary>
81-
/// Gets or sets whether to populate the dropdown list with initial items
82-
/// immediately after the component first renders.
83-
/// Defaults to true. Set to false to only populate when the user interacts (types or focuses, depending on other settings).
84-
/// </summary>
85-
[Parameter]
86-
public bool PopulateListOnFirstRender { get; set; } = true; // Default to the behavior we just added
87-
// --- END NEW PARAMETER ---
88-
8981
/// <summary>
9082
/// IStringLocalizer service instance
9183
/// </summary>
@@ -100,6 +92,7 @@ public partial class AutoComplete
10092
[NotNull]
10193
private ILogger<AutoComplete>? Logger { get; set; }
10294

95+
10396
/// <summary>
10497
/// Gets the string setting for automatically displaying the dropdown when focused
10598
/// </summary>
@@ -142,56 +135,11 @@ protected override void OnParametersSet()
142135
/// </summary>
143136
protected override async Task OnAfterRenderAsync(bool firstRender)
144137
{
145-
await base.OnAfterRenderAsync(firstRender); // Call base implementation first
146-
138+
await base.OnAfterRenderAsync(firstRender);
147139
if (firstRender)
148140
{
149-
// Original logic: Set initial visual value of input via JS
141+
// STUTTER FIX: Set initial visual value of input via JS
150142
await JSSetInputValue(Value);
151-
152-
// --- MODIFIED SECTION ---
153-
// Check the new parameter before populating/rendering the initial list
154-
if (PopulateListOnFirstRender) // <--- Check the new parameter
155-
{
156-
// 1. Populate the _filterItems list based on initial state
157-
try
158-
{
159-
if (OnCustomFilter != null)
160-
{
161-
var initialItems = await OnCustomFilter(Value ?? "");
162-
_filterItems = [.. initialItems];
163-
}
164-
else if (!string.IsNullOrEmpty(Value))
165-
{
166-
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
167-
var items = IsLikeMatch
168-
? Items.Where(s => s.Contains(Value, comparison))
169-
: Items.Where(s => s.StartsWith(Value, comparison));
170-
_filterItems = [.. items];
171-
}
172-
else
173-
{
174-
_filterItems = [.. Items];
175-
}
176-
177-
if (DisplayCount.HasValue && _filterItems != null)
178-
{
179-
_filterItems = [.. _filterItems.Take(DisplayCount.Value)];
180-
}
181-
}
182-
catch (Exception ex)
183-
{
184-
Logger?.LogError(ex, "Error during initial population of AutoComplete dropdown for ID {Id}", Id);
185-
_filterItems = [];
186-
}
187-
188-
// 2. Trigger a re-render of *only* the dropdown fragment
189-
if (_dropdown != null)
190-
{
191-
_dropdown.Render();
192-
}
193-
}
194-
// --- End of modified section ---
195143
}
196144
}
197145

@@ -254,37 +202,28 @@ public async Task PerformFilteringAndCommitValue(string val)
254202
}
255203

256204
// Original filtering logic
257-
try
205+
if (OnCustomFilter != null)
206+
{
207+
var items = await OnCustomFilter(val);
208+
_filterItems = [.. items];
209+
}
210+
else if (string.IsNullOrEmpty(val))
258211
{
259-
if (OnCustomFilter != null)
260-
{
261-
var items = await OnCustomFilter(val);
262-
_filterItems = [.. items];
263-
}
264-
else if (string.IsNullOrEmpty(val))
265-
{
266-
_filterItems = [.. Items];
267-
}
268-
else
269-
{
270-
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
271-
var items = IsLikeMatch
272-
? Items.Where(s => s.Contains(val, comparison))
273-
: Items.Where(s => s.StartsWith(val, comparison));
274-
_filterItems = [.. items];
275-
}
276-
277-
if (DisplayCount != null && _filterItems != null) // Check _filterItems for null after potential filtering
278-
{
279-
_filterItems = [.. _filterItems.Take(DisplayCount.Value)];
280-
}
212+
_filterItems = [.. Items];
281213
}
282-
catch (Exception ex) // Optional: Add error handling for filtering
214+
else
283215
{
284-
Logger?.LogError(ex, "Error during filtering/committing value for AutoComplete ID {Id}", Id);
285-
_filterItems = []; // Set to empty list on error
216+
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
217+
var items = IsLikeMatch
218+
? Items.Where(s => s.Contains(val, comparison))
219+
: Items.Where(s => s.StartsWith(val, comparison));
220+
_filterItems = [.. items];
286221
}
287222

223+
if (DisplayCount != null)
224+
{
225+
_filterItems = [.. _filterItems.Take(DisplayCount.Value)];
226+
}
288227

289228
// Update dropdown UI using targeted render (original approach)
290229
_shouldRender = false;

0 commit comments

Comments
 (0)