diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor index 81b19bc12cf..04317f29135 100644 --- a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor +++ b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor @@ -8,7 +8,7 @@ }
- + @if (ShowIcon) { diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs index 6039190deb8..05afb3ef97b 100644 --- a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs +++ b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs @@ -228,6 +228,12 @@ public string? Format [Parameter] public bool DisplayDisabledDayAsEmpty { get; set; } + /// + /// 获得/设置 失去焦点回调方法 默认 null + /// + [Parameter] + public Func? OnBlurAsync { get; set; } + [Inject] [NotNull] private IStringLocalizer>? Localizer { get; set; } @@ -437,4 +443,15 @@ protected override bool TryParseValueFromString(string value, [MaybeNullWhen(fal } private string? ReadonlyString => IsEditable ? null : "readonly"; + + /// + /// + /// + protected virtual async Task OnBlur() + { + if (OnBlurAsync != null) + { + await OnBlurAsync(Value); + } + } } diff --git a/test/UnitTest/Components/DateTimePickerTest.cs b/test/UnitTest/Components/DateTimePickerTest.cs index 842a8b4089c..a2e5df0a3b2 100644 --- a/test/UnitTest/Components/DateTimePickerTest.cs +++ b/test/UnitTest/Components/DateTimePickerTest.cs @@ -1239,6 +1239,23 @@ public async Task OnGetDisabledDaysCallback_Ok() cut.Instance.ClearDisabledDays(); } + [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); + } + class MockDateTimePicker : DatePickerBody { public static bool GetSafeYearDateTime_Ok()