diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 09d572d9971..d50fa55ed68 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.8.1 + 9.8.2-beta01 diff --git a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs index cea7a398424..6c33c822087 100644 --- a/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs +++ b/src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs @@ -303,7 +303,7 @@ protected override void OnParametersSet() } else { - SelectedValue = Value == null ? DateTime.MinValue : (DateTime)(object)Value; + SelectedValue = Value == null ? (MinValue ?? DateTime.MinValue) : (DateTime)(object)Value; } if (MinValue > SelectedValue) diff --git a/test/UnitTest/Components/DateTimePickerTest.cs b/test/UnitTest/Components/DateTimePickerTest.cs index 4bf31c1d247..8cb7b56ba3f 100644 --- a/test/UnitTest/Components/DateTimePickerTest.cs +++ b/test/UnitTest/Components/DateTimePickerTest.cs @@ -132,7 +132,7 @@ public void DisplayMinValueAsEmpty_NullableDateTimeOffset() } [Fact] - public void OnClear_Ok() + public async Task OnClear_Ok() { var cut = Context.RenderComponent>(pb => { @@ -143,14 +143,14 @@ public void OnClear_Ok() // 点击 0001-01-01 单元格 var cell = cut.Find(".current .cell"); - cut.InvokeAsync(() => cell.Click()); + await cut.InvokeAsync(() => cell.Click()); // 文本框内容 var input = cut.Find(".datetime-picker-input"); Assert.Equal($"{DateTime.MinValue:yyyy-MM-dd}", input.GetAttribute("value")); // 点击清空按钮 var clear = cut.Find(".picker-panel-footer button"); - cut.InvokeAsync(() => clear.Click()); + await cut.InvokeAsync(() => clear.Click()); // 文本框内容 为 "" input = cut.Find(".datetime-picker-input"); @@ -162,7 +162,7 @@ public void OnClear_Ok() pb.Add(a => a.DisplayMinValueAsEmpty, true); }); cell = cut.Find(".current .cell"); - cut.InvokeAsync(() => cell.Click()); + await cut.InvokeAsync(() => cell.Click()); // 文本框内容 input = cut.Find(".datetime-picker-input"); @@ -170,11 +170,20 @@ public void OnClear_Ok() // 点击清空按钮 clear = cut.Find(".picker-panel-footer button"); - cut.InvokeAsync(() => clear.Click()); + await cut.InvokeAsync(() => clear.Click()); // 文本框内容 为 "" input = cut.Find(".datetime-picker-input"); Assert.Equal("", input.GetAttribute("value")); + + // 设置最小时间值 + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.MinValue, DateTime.Today); + pb.Add(a => a.Value, null); + }); + clear = cut.Find(".picker-panel-footer button"); + await cut.InvokeAsync(() => clear.Click()); } [Fact] @@ -249,7 +258,10 @@ public void MaxValue_Ok() [Fact] public void MinValue_Ok() { - var cut = Context.RenderComponent>(builder => builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1))); + var cut = Context.RenderComponent>(builder => + { + builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1)); + }); cut.SetParametersAndRender(pb => {