diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 3de6e657049..7751d1e107b 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.1.7 + 9.1.8 diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.cs b/src/BootstrapBlazor/Components/Select/Select.razor.cs index a89e0530e50..3b1b047676c 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.cs +++ b/src/BootstrapBlazor/Components/Select/Select.razor.cs @@ -235,6 +235,13 @@ public partial class Select : ISelect [NotNull] private IStringLocalizer>? Localizer { get; set; } + /// + /// 获得/设置 服务实例 + /// + [Inject] + [NotNull] + private ILookupService? InjectLookupService { get; set; } + /// /// 获得 input 组件 Id 方法 /// @@ -371,13 +378,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender) private async Task> GetItemsAsync() { IEnumerable? 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; + /// /// 获得/设置 数据总条目 /// diff --git a/test/UnitTest/Components/EditorFormTest.cs b/test/UnitTest/Components/EditorFormTest.cs index b6a07f9cfce..949717bd9bb 100644 --- a/test/UnitTest/Components/EditorFormTest.cs +++ b/test/UnitTest/Components/EditorFormTest.cs @@ -438,6 +438,7 @@ public async Task LookupServiceKey_Ok() builder.CloseComponent(); }); }); + cut.WaitForAssertion(() => cut.Contains("LookupService-Test-1")); var select = cut.FindComponent>(); var lookupService = Context.Services.GetRequiredService(); var lookup = await lookupService.GetItemsAsync("FooLookup", ""); @@ -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>(); var lookup = await lookupService.GetItemsAsync("FooLookup", ""); Assert.NotNull(lookup); diff --git a/test/UnitTest/Components/SelectTest.cs b/test/UnitTest/Components/SelectTest.cs index 015d83b1a59..167d91b7192 100644 --- a/test/UnitTest/Components/SelectTest.cs +++ b/test/UnitTest/Components/SelectTest.cs @@ -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>(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() { diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 857c74d238f..36144633b64 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -7673,7 +7673,6 @@ public async Task GetValue_LookupServiceKey() pb.Add(a => a.LookupService, new MockLookupServiceAsync()); }); await cut.InvokeAsync(() => table.Instance.QueryAsync()); - cut.WaitForElement("[data-bs-original-title=\"LookupService-Test-True-async\"]"); } [Fact]