From fa2f6e25d5ebaa7d290c036d920b044df14c8772 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Thu, 24 Oct 2024 11:52:27 +0800 Subject: [PATCH 1/3] feat(BootstrapInput): add OnBlurAsync parameter --- .../Components/Input/BootstrapInput.razor | 2 +- .../Components/Input/BootstrapInput.razor.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor index a6a245944b7..36b60fc0ac0 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor @@ -7,4 +7,4 @@ } - + diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs index 22d872b6409..633bd8252cb 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs @@ -22,6 +22,12 @@ public partial class BootstrapInput [Parameter] public bool AutoSetDefaultWhenNull { get; set; } + /// + /// 获得/设置 失去焦点回调方法 默认 null + /// + [Parameter] + public Func? OnBlurAsync { get; set; } + private string? ReadonlyString => Readonly ? "true" : null; /// @@ -47,4 +53,15 @@ protected override bool TryParseValueFromString(string value, [MaybeNullWhen(fal } return ret; } + + /// + /// OnBlur 方法 + /// + protected virtual async Task OnBlur() + { + if (OnBlurAsync != null) + { + await OnBlurAsync(Value); + } + } } From 92290c610944a1607b0e9e790bec50be4eed9024 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Thu, 24 Oct 2024 11:53:53 +0800 Subject: [PATCH 2/3] =?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/InputTest.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/UnitTest/Components/InputTest.cs b/test/UnitTest/Components/InputTest.cs index dfcb86d42ec..ead43b649aa 100644 --- a/test/UnitTest/Components/InputTest.cs +++ b/test/UnitTest/Components/InputTest.cs @@ -356,4 +356,21 @@ public void OnValueChanged_Ok() Assert.Equal("Test_Test-Test_Test", val); }); } + + [Fact] + public async Task OnBlurAsync_Ok() + { + var blur = false; + var cut = Context.RenderComponent>(builder => + { + builder.Add(a => a.OnBlurAsync, v => + { + blur = true; + return Task.CompletedTask; + }); + }); + var input = cut.Find("input"); + await cut.InvokeAsync(() => { input.Blur(); }); + Assert.True(blur); + } } From bc86132a281fe608ebdf5d9e64e751cf24e22ce9 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Thu, 24 Oct 2024 12:06:02 +0800 Subject: [PATCH 3/3] =?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 --- test/UnitTest/Utils/UtilityTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs index d025d717e44..fb29fd4c948 100644 --- a/test/UnitTest/Utils/UtilityTest.cs +++ b/test/UnitTest/Utils/UtilityTest.cs @@ -256,7 +256,7 @@ public void CreateComponentByFieldType_Ok() var editor = new MockNullDisplayNameColumn("Name", typeof(string)) { Readonly = true }; var fragment = new RenderFragment(builder => builder.CreateComponentByFieldType(new BootstrapBlazorRoot(), editor, new Foo() { Name = "Test-Component" })); var cut = Context.Render(builder => builder.AddContent(0, fragment)); - Assert.Contains("class=\"form-control\" disabled=\"disabled\" value=\"Test-Component\"", cut.Markup); + Assert.Contains("value=\"Test-Component\"", cut.Markup); } [Fact]