mirror of
https://github.com/dotnetcore/BootstrapBlazor.git
synced 2025-12-20 10:26:41 +08:00
feat(BootstrapInput): add OnBlurAsync parameter (#4521)
* feat(BootstrapInput): add OnBlurAsync parameter * test: 增加单元测试 * test: 更新单元测试
This commit is contained in:
@@ -7,4 +7,4 @@
|
||||
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
|
||||
}
|
||||
|
||||
<input @attributes="@AdditionalAttributes" type="@Type" placeholder="@PlaceHolder" id="@Id" readonly="@ReadonlyString" class="@ClassName" disabled="@Disabled" @bind-value="CurrentValueAsString" @bind-value:event="@EventString" @ref="FocusElement" />
|
||||
<input @attributes="@AdditionalAttributes" type="@Type" placeholder="@PlaceHolder" id="@Id" readonly="@ReadonlyString" class="@ClassName" disabled="@Disabled" @bind-value="CurrentValueAsString" @bind-value:event="@EventString" @onblur="@OnBlur" @ref="FocusElement" />
|
||||
|
||||
@@ -22,6 +22,12 @@ public partial class BootstrapInput<TValue>
|
||||
[Parameter]
|
||||
public bool AutoSetDefaultWhenNull { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 失去焦点回调方法 默认 null
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<TValue, Task>? OnBlurAsync { get; set; }
|
||||
|
||||
private string? ReadonlyString => Readonly ? "true" : null;
|
||||
|
||||
/// <summary>
|
||||
@@ -47,4 +53,15 @@ public partial class BootstrapInput<TValue>
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnBlur 方法
|
||||
/// </summary>
|
||||
protected virtual async Task OnBlur()
|
||||
{
|
||||
if (OnBlurAsync != null)
|
||||
{
|
||||
await OnBlurAsync(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,4 +356,21 @@ public class InputTest : BootstrapBlazorTestBase
|
||||
Assert.Equal("Test_Test-Test_Test", val);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OnBlurAsync_Ok()
|
||||
{
|
||||
var blur = false;
|
||||
var cut = Context.RenderComponent<BootstrapInput<string>>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class UtilityTest : BootstrapBlazorTestBase
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user