Skip to content

Commit 9328c8a

Browse files
authored
fix(DateTimePicker): can't clear value when set MinValue (#6428)
* fix: 修复设置 MinValue 值导清空按钮不工作问题 * test: 更新单元测试 * chore: bump version 9.8.2-beta01
1 parent 3570038 commit 9328c8a

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.8.1</Version>
4+
<Version>9.8.2-beta01</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ protected override void OnParametersSet()
303303
}
304304
else
305305
{
306-
SelectedValue = Value == null ? DateTime.MinValue : (DateTime)(object)Value;
306+
SelectedValue = Value == null ? (MinValue ?? DateTime.MinValue) : (DateTime)(object)Value;
307307
}
308308

309309
if (MinValue > SelectedValue)

test/UnitTest/Components/DateTimePickerTest.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void DisplayMinValueAsEmpty_NullableDateTimeOffset()
132132
}
133133

134134
[Fact]
135-
public void OnClear_Ok()
135+
public async Task OnClear_Ok()
136136
{
137137
var cut = Context.RenderComponent<DateTimePicker<DateTime?>>(pb =>
138138
{
@@ -143,14 +143,14 @@ public void OnClear_Ok()
143143

144144
// 点击 0001-01-01 单元格
145145
var cell = cut.Find(".current .cell");
146-
cut.InvokeAsync(() => cell.Click());
146+
await cut.InvokeAsync(() => cell.Click());
147147
// 文本框内容
148148
var input = cut.Find(".datetime-picker-input");
149149
Assert.Equal($"{DateTime.MinValue:yyyy-MM-dd}", input.GetAttribute("value"));
150150

151151
// 点击清空按钮
152152
var clear = cut.Find(".picker-panel-footer button");
153-
cut.InvokeAsync(() => clear.Click());
153+
await cut.InvokeAsync(() => clear.Click());
154154

155155
// 文本框内容 为 ""
156156
input = cut.Find(".datetime-picker-input");
@@ -162,19 +162,28 @@ public void OnClear_Ok()
162162
pb.Add(a => a.DisplayMinValueAsEmpty, true);
163163
});
164164
cell = cut.Find(".current .cell");
165-
cut.InvokeAsync(() => cell.Click());
165+
await cut.InvokeAsync(() => cell.Click());
166166

167167
// 文本框内容
168168
input = cut.Find(".datetime-picker-input");
169169
Assert.Equal($"{DateTime.Today:yyyy-MM-dd}", input.GetAttribute("value"));
170170

171171
// 点击清空按钮
172172
clear = cut.Find(".picker-panel-footer button");
173-
cut.InvokeAsync(() => clear.Click());
173+
await cut.InvokeAsync(() => clear.Click());
174174

175175
// 文本框内容 为 ""
176176
input = cut.Find(".datetime-picker-input");
177177
Assert.Equal("", input.GetAttribute("value"));
178+
179+
// 设置最小时间值
180+
cut.SetParametersAndRender(pb =>
181+
{
182+
pb.Add(a => a.MinValue, DateTime.Today);
183+
pb.Add(a => a.Value, null);
184+
});
185+
clear = cut.Find(".picker-panel-footer button");
186+
await cut.InvokeAsync(() => clear.Click());
178187
}
179188

180189
[Fact]
@@ -249,7 +258,10 @@ public void MaxValue_Ok()
249258
[Fact]
250259
public void MinValue_Ok()
251260
{
252-
var cut = Context.RenderComponent<DateTimePicker<DateTime>>(builder => builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1)));
261+
var cut = Context.RenderComponent<DateTimePicker<DateTime>>(builder =>
262+
{
263+
builder.Add(a => a.MinValue, DateTime.Today.AddDays(-1));
264+
});
253265

254266
cut.SetParametersAndRender(pb =>
255267
{

0 commit comments

Comments
 (0)