From 335f0a6d6ddb3c68778bc1ec330ed583a8635460 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 17:09:21 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=8A=B6=E6=80=81=E5=90=8E=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E4=B8=8B=E6=8B=89=E6=A1=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Dropdown/Dropdown.razor | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor index 458c13ee96c..413eda5acc0 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor @@ -22,31 +22,28 @@ { } - @if (!IsDisabled) - { -
- @if (ItemsTemplate == null) +
+ @if (ItemsTemplate == null) + { + @foreach (var item in GetItems()) { - @foreach (var item in GetItems()) + if (ItemTemplate != null) { - if (ItemTemplate != null) - { - @ItemTemplate.Invoke(item) - } - else if (item.IsDisabled) - { -
@item.Text
- } - else - { -
@item.Text
- } + @ItemTemplate.Invoke(item) + } + else if (item.IsDisabled) + { +
@item.Text
+ } + else + { +
@item.Text
} } - else - { - @ItemsTemplate - } -
- } + } + else + { + @ItemsTemplate + } +
From 88245586a096bc7bbacdc455c9c03798699c22f1 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 17:10:26 +0800 Subject: [PATCH 2/9] chore: bump version 9.1.3 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 08cdf115551..26e16d5f31c 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.1.3-beta07 + 9.1.3 From f0c83570a0bf160ee6a5365dc7b8edfdde16d23a Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 17:19:31 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Item=20?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Dropdown/Dropdown.razor | 2 +- .../Components/Dropdown/Dropdown.razor.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor index 413eda5acc0..26b69d56ad4 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor @@ -33,7 +33,7 @@ } else if (item.IsDisabled) { -
@item.Text
+
@item.Text
} else { diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs index 08985d29657..61d0c09f0f9 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs @@ -62,6 +62,15 @@ public partial class Dropdown .AddClass("active", () => item.Value == CurrentValueAsString) .Build(); + /// + /// 获得/设置 设置当前项是否 Active 方法 + /// + /// + /// + protected string? DisableItem(SelectedItem item) => CssBuilder.Default("dropdown-item") + .AddClass("is-disabled", item.IsDisabled) + .Build(); + /// /// 获得/设置 颜色 默认 Color.None 无设置 /// From c54980806d6f2335b95a98c5ab2c7362e05367c5 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 17:19:38 +0800 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DropdownTest.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/UnitTest/Components/DropdownTest.cs b/test/UnitTest/Components/DropdownTest.cs index dac0f0cd6f4..f2a7a4838e6 100644 --- a/test/UnitTest/Components/DropdownTest.cs +++ b/test/UnitTest/Components/DropdownTest.cs @@ -226,17 +226,14 @@ public void Disabled_Ok() { var cut = Context.RenderComponent>(pb => { - pb.Add(a => a.IsDisabled, true); + pb.Add(a => a.IsDisabled, false); pb.Add(a => a.Items, new SelectedItem[] { new("1", "Test1") { IsDisabled = true }, new("2", "Test2") }); }); - // 禁用组件不生成 下拉菜单 - cut.DoesNotContain("dropdown-menu"); - - cut.SetParametersAndRender(pb => pb.Add(a => a.IsDisabled, false)); + cut.Contains("
Test1
"); } [Fact] From f49f2fdf345e7f18838475de5096f9179e4b45cb Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 18:11:02 +0800 Subject: [PATCH 5/9] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs index 61d0c09f0f9..69848af544a 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs @@ -68,7 +68,7 @@ public partial class Dropdown /// /// protected string? DisableItem(SelectedItem item) => CssBuilder.Default("dropdown-item") - .AddClass("is-disabled", item.IsDisabled) + .AddClass("disabled", item.IsDisabled) .Build(); /// From a39a354e101490ddb70ca480bc85ec76c544644a Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 18:17:56 +0800 Subject: [PATCH 6/9] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectGeneric/SelectGeneric.razor.cs | 14 +++++++++++++- test/UnitTest/Components/SelectGenericTest.cs | 13 +++---------- test/UnitTest/Components/SelectTest.cs | 10 +++++----- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs index 7107cf8a963..9f72a898ff1 100644 --- a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs +++ b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs @@ -391,7 +391,7 @@ private async Task SearchTextChanged(string val) /// /// /// - protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, nameof(ConfirmSelectedItem)); + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { ConfirmMethodCallback = nameof(ConfirmSelectedItem), SearchMethodCallback = nameof(TriggerOnSearch) }); /// /// 客户端回车回调方法 @@ -408,6 +408,18 @@ public async Task ConfirmSelectedItem(int index) } } + /// + /// 客户端搜索栏回调方法 + /// + /// + /// + [JSInvokable] + public async Task TriggerOnSearch(string searchText) + { + await SearchTextChanged(searchText); + StateHasChanged(); + } + /// /// 下拉框选项点击时调用此方法 /// diff --git a/test/UnitTest/Components/SelectGenericTest.cs b/test/UnitTest/Components/SelectGenericTest.cs index 07aeef6caa5..71f325b75b0 100644 --- a/test/UnitTest/Components/SelectGenericTest.cs +++ b/test/UnitTest/Components/SelectGenericTest.cs @@ -13,13 +13,6 @@ namespace UnitTest.Components; public class SelectGenericTest : BootstrapBlazorTestBase { - [Fact] - public void SeletectedItem_Ok() - { - var item = new SelectedItem(null!, "Text"); - Assert.Equal(item.Value, string.Empty); - } - [Fact] public async Task OnSearchTextChanged_Null() { @@ -42,7 +35,7 @@ await ctx.InvokeAsync(async () => await ctx.Instance.ConfirmSelectedItem(0); // 搜索 T - ctx.Find(".search-text").Input("T"); + await ctx.Instance.TriggerOnSearch("T"); await ctx.Instance.ConfirmSelectedItem(0); }); @@ -68,9 +61,9 @@ await ctx.InvokeAsync(async () => }); }); - await ctx.InvokeAsync(() => + await ctx.InvokeAsync(async () => { - ctx.Find(".search-text").Input("T"); + await ctx.Instance.TriggerOnSearch("T"); }); cut.DoesNotContain("Test2"); } diff --git a/test/UnitTest/Components/SelectTest.cs b/test/UnitTest/Components/SelectTest.cs index e8499a8be79..da97baee2d3 100644 --- a/test/UnitTest/Components/SelectTest.cs +++ b/test/UnitTest/Components/SelectTest.cs @@ -35,7 +35,7 @@ await ctx.InvokeAsync(async () => await ctx.Instance.ConfirmSelectedItem(0); // 搜索 T - ctx.Find(".search-text").Input("T"); + await ctx.Instance.TriggerOnSearch("T"); await ctx.Instance.ConfirmSelectedItem(0); }); @@ -61,9 +61,9 @@ await ctx.InvokeAsync(async () => }); }); - await ctx.InvokeAsync(() => + await ctx.InvokeAsync(async () => { - ctx.Find(".search-text").Input("T"); + await ctx.Instance.TriggerOnSearch("T"); }); cut.DoesNotContain("Test2"); } @@ -663,7 +663,7 @@ public async Task IsVirtualize_Items_Clearable_Ok() // 期望 UI 显示值为默认值 // 期望 下拉框为全数据 var input = cut.Find(".search-text"); - await cut.InvokeAsync(() => input.Input("2")); + await cut.InvokeAsync(() => cut.Instance.TriggerOnSearch("2")); // 下拉框仅显示一个选项 Test2 var items = cut.FindAll(".dropdown-item"); @@ -721,7 +721,7 @@ public async Task IsVirtualize_OnQueryAsync_Clearable_Ok() // 期望 UI 显示值为默认值 // 期望 下拉框为全数据 var input = cut.Find(".search-text"); - await cut.InvokeAsync(() => input.Input("2")); + await cut.InvokeAsync(() => cut.Instance.TriggerOnSearch("2")); // 下拉框仅显示一个选项 Test2 var items = cut.FindAll(".dropdown-item"); From 9fb8c1322d7f20b8ffa6f0ac2012402c8625d223 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Sat, 14 Dec 2024 18:26:13 +0800 Subject: [PATCH 7/9] =?UTF-8?q?refactor:=20=E5=90=8C=E6=AD=A5=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectGeneric/SelectGeneric.razor | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor index f5764ae07d9..98737b6142b 100644 --- a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor +++ b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor @@ -31,15 +31,15 @@ }