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);
+ }
+ }
}
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);
+ }
}
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]