Skip to content

Commit

Permalink
refactor(Select): auto load data on virtual mode (#4852)
Browse files Browse the repository at this point in the history
* refactor: 修复首次加载问题

* test: 更新单元测试

* chore: bump version 9.1.4
  • Loading branch information
ArgoZhang authored Dec 15, 2024
1 parent 8b246b8 commit a759930
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.1.3</Version>
<Version>9.1.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 21 additions & 1 deletion src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,21 @@ protected override void OnParametersSet()
SelectedItem = null;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

if (firstRender)
{
await RefreshVirtualizeElement();
StateHasChanged();
}
}

/// <summary>
/// 获得/设置 数据总条目
/// </summary>
Expand Down Expand Up @@ -356,7 +371,12 @@ private async Task SearchTextChanged(string val)
{
_itemsCache = null;
SearchText = val;
if (OnQueryAsync != null)
await RefreshVirtualizeElement();
}

private async Task RefreshVirtualizeElement()
{
if (IsVirtualize && OnQueryAsync != null)
{
// 通过 ItemProvider 提供数据
await VirtualizeElement.RefreshDataAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ protected override void OnParametersSet()
SelectedItem = null;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

if (firstRender)
{
await RefreshVirtualizeElement();
StateHasChanged();
}
}

/// <summary>
/// 获得/设置 数据总条目
/// </summary>
Expand Down Expand Up @@ -379,8 +394,12 @@ private async Task SearchTextChanged(string val)
{
SearchText = val;
_itemsCache = null;
await RefreshVirtualizeElement();
}

if (OnQueryAsync != null)
private async Task RefreshVirtualizeElement()
{
if (IsVirtualize && OnQueryAsync != null)
{
// 通过 ItemProvider 提供数据
await VirtualizeElement.RefreshDataAsync();
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public async Task IsVirtualize_BindValue()
});

var input = cut.Find(".form-select");
Assert.Null(input.GetAttribute("value"));
Assert.Equal("3", input.GetAttribute("value"));

var select = cut.Instance;
Assert.Equal("3", select.Value?.Value);
Expand Down

0 comments on commit a759930

Please sign in to comment.