Skip to content

Commit a759930

Browse files
authored
refactor(Select): auto load data on virtual mode (#4852)
* refactor: 修复首次加载问题 * test: 更新单元测试 * chore: bump version 9.1.4
1 parent 8b246b8 commit a759930

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.1.3</Version>
4+
<Version>9.1.4</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Select/Select.razor.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ protected override void OnParametersSet()
323323
SelectedItem = null;
324324
}
325325

326+
/// <summary>
327+
/// <inheritdoc/>
328+
/// </summary>
329+
/// <returns></returns>
330+
protected override async Task OnAfterRenderAsync(bool firstRender)
331+
{
332+
await base.OnAfterRenderAsync(firstRender);
333+
334+
if (firstRender)
335+
{
336+
await RefreshVirtualizeElement();
337+
StateHasChanged();
338+
}
339+
}
340+
326341
/// <summary>
327342
/// 获得/设置 数据总条目
328343
/// </summary>
@@ -356,7 +371,12 @@ private async Task SearchTextChanged(string val)
356371
{
357372
_itemsCache = null;
358373
SearchText = val;
359-
if (OnQueryAsync != null)
374+
await RefreshVirtualizeElement();
375+
}
376+
377+
private async Task RefreshVirtualizeElement()
378+
{
379+
if (IsVirtualize && OnQueryAsync != null)
360380
{
361381
// 通过 ItemProvider 提供数据
362382
await VirtualizeElement.RefreshDataAsync();

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ protected override void OnParametersSet()
346346
SelectedItem = null;
347347
}
348348

349+
/// <summary>
350+
/// <inheritdoc/>
351+
/// </summary>
352+
/// <returns></returns>
353+
protected override async Task OnAfterRenderAsync(bool firstRender)
354+
{
355+
await base.OnAfterRenderAsync(firstRender);
356+
357+
if (firstRender)
358+
{
359+
await RefreshVirtualizeElement();
360+
StateHasChanged();
361+
}
362+
}
363+
349364
/// <summary>
350365
/// 获得/设置 数据总条目
351366
/// </summary>
@@ -379,8 +394,12 @@ private async Task SearchTextChanged(string val)
379394
{
380395
SearchText = val;
381396
_itemsCache = null;
397+
await RefreshVirtualizeElement();
398+
}
382399

383-
if (OnQueryAsync != null)
400+
private async Task RefreshVirtualizeElement()
401+
{
402+
if (IsVirtualize && OnQueryAsync != null)
384403
{
385404
// 通过 ItemProvider 提供数据
386405
await VirtualizeElement.RefreshDataAsync();

test/UnitTest/Components/SelectTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public async Task IsVirtualize_BindValue()
773773
});
774774

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

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

0 commit comments

Comments
 (0)