Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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.7</Version>
<Version>9.1.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ public partial class Select<TValue> : ISelect
[NotNull]
private IStringLocalizer<Select<TValue>>? Localizer { get; set; }

/// <summary>
/// 获得/设置 <see cref="ILookupService"/> 服务实例
/// </summary>
[Inject]
[NotNull]
private ILookupService? InjectLookupService { get; set; }

/// <summary>
/// 获得 input 组件 Id 方法
/// </summary>
Expand Down Expand Up @@ -371,13 +378,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
private async Task<IEnumerable<SelectedItem>> GetItemsAsync()
{
IEnumerable<SelectedItem>? items = null;
if (LookupService != null)
if (!string.IsNullOrEmpty(LookupServiceKey))
{
items = await LookupService.GetItemsByKeyAsync(LookupServiceKey, LookupServiceData);
items = await GetLookupService().GetItemsAsync(LookupServiceKey, LookupServiceData);
}
return items ?? [];
}

private ILookupService GetLookupService() => LookupService ?? InjectLookupService;

/// <summary>
/// 获得/设置 数据总条目
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion test/UnitTest/Components/EditorFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ public async Task LookupServiceKey_Ok()
builder.CloseComponent();
});
});
cut.WaitForAssertion(() => cut.Contains("LookupService-Test-1"));
var select = cut.FindComponent<Select<string>>();
var lookupService = Context.Services.GetRequiredService<ILookupService>();
var lookup = await lookupService.GetItemsAsync("FooLookup", "");
Expand Down Expand Up @@ -471,7 +472,7 @@ public async Task LookupService_Ok()
builder.CloseComponent();
});
});
cut.WaitForElements(".select");
cut.WaitForAssertion(() => cut.Contains("LookupService-Test-1-async"));
var select = cut.FindComponent<Select<string>>();
var lookup = await lookupService.GetItemsAsync("FooLookup", "");
Assert.NotNull(lookup);
Expand Down
12 changes: 12 additions & 0 deletions test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public void Disabled_Ok()
Assert.Contains("dropdown-item active disabled", cut.Markup);
}

[Fact]
public void LookupService_Ok()
{
// 不给 Items 时走 LookupService
var cut = Context.RenderComponent<Select<string>>(pb =>
{
pb.Add(a => a.LookupServiceKey, "FooLookup");
});
cut.WaitForAssertion(() => cut.Contains("LookupService-Test-1"));
Assert.Equal(2, cut.Instance.Items.Count());
}

[Fact]
public void IsClearable_Ok()
{
Expand Down
Loading