Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix the Autocomplete search rendering on slow connections #2820

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading