Skip to content

Commit

Permalink
Fix the Autocomplete search rendreding on slow connections (#2820)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoituron authored Oct 17, 2024
1 parent a396f75 commit cae7548
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3517,6 +3517,7 @@
Gets or sets the dialog position:
left (full height), right (full height)
or screen middle (using Width and Height properties).
HorizontalAlignment.Stretch is not supported for this property.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.DialogParameters.Title">
Expand Down Expand Up @@ -5675,6 +5676,9 @@
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentAutocomplete`1.SelectableItem">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentAutocomplete`1.ShouldRender">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentAutocomplete`1.InputHandlerAsync(Microsoft.AspNetCore.Components.ChangeEventArgs)">
<summary />
</member>
Expand Down Expand Up @@ -13869,6 +13873,11 @@
The content is aligned to the end.
</summary>
</member>
<member name="F:Microsoft.FluentUI.AspNetCore.Components.HorizontalAlignment.Stretch">
<summary>
The content is stretched to fill the available space.
</summary>
</member>
<member name="T:Microsoft.FluentUI.AspNetCore.Components.HorizontalPosition">
<summary>
Describes the horizontal positioning of a <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentAnchoredRegion"/>.
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Components/List/FluentAutocomplete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class FluentAutocomplete<TOption> : ListComponentBase<TOption> wh
public new FluentTextField? Element { get; set; } = default!;
private Virtualize<TOption>? VirtualizationContainer { get; set; }
private readonly Debounce _debounce = new();
private bool _shouldRender = true;

/// <summary>
/// Initializes a new instance of the <see cref="FluentAutocomplete{TOption}"/> class.
Expand Down Expand Up @@ -267,6 +268,9 @@ private string ComponentWidth
/// <summary />
private TOption? SelectableItem { get; set; }

/// <summary />
protected override bool ShouldRender() => _shouldRender;

/// <summary />
protected override async Task InputHandlerAsync(ChangeEventArgs e)
{
Expand All @@ -275,6 +279,8 @@ protected override async Task InputHandlerAsync(ChangeEventArgs e)
return;
}

_shouldRender = false;

ValueText = e.Value?.ToString() ?? string.Empty;
await RaiseValueTextChangedAsync(ValueText);

Expand Down Expand Up @@ -312,6 +318,9 @@ protected override async Task InputHandlerAsync(ChangeEventArgs e)
{
await VirtualizationContainer.RefreshDataAsync();
}

_shouldRender = true;
StateHasChanged();
}

private ValueTask<ItemsProviderResult<TOption>> LoadFilteredItemsAsync(ItemsProviderRequest request)
Expand Down

0 comments on commit cae7548

Please sign in to comment.