Skip to content

Commit 4d688cb

Browse files
authored
feat(DateTimeRange): add AutoClose parameter (#5802)
* feat: 增加 AutoClose 参数 * doc: 更新文档 * test: 更新单元测试 * doc: 增加 AutoClose 说明文档 * chore: bump version 9.5.5
1 parent 6bea102 commit 4d688cb

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

src/BootstrapBlazor.Server/Components/Samples/DateTimeRanges.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<DateTimeRange @bind-Value="@BindValueDemoDateTimeRangeValue" OnValueChanged="v => BindValueDemoOnValueChanged(v, 1)"
4040
ShowLunar="_showLunar" ShowSolarTerm="_showSolarTerm"
4141
ShowFestivals="_showFestivals" ShowHolidays="_showHolidays"
42-
ShowSelectedValue="true"></DateTimeRange>
42+
ShowSelectedValue="true" AutoClose="true"></DateTimeRange>
4343
</div>
4444
<div class="col-12 col-sm-6">
4545
<BootstrapInputGroup>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,7 @@
39873987
"NormalTitle": "Basic skills",
39883988
"NormalIntro": "Take 'day' as the basic unit, select a period of time",
39893989
"BindValueTitle": "Data two-way binding",
3990-
"BindValueIntro": "Click the confirm button, the time selection box value is the same as the text box value",
3990+
"BindValueIntro": "Click the confirm button, the time selection box value is the same as the text box value. Enable auto-close by setting <code>AutoClose=\"true\"</code>. Directly display the selected value by setting <code>ShowSelectedValue=\"true\"</code>",
39913991
"MaxMinValueTitle": "Max and Min",
39923992
"MaxMinValueIntro": "set time range",
39933993
"DisabledTitle": "Disabled",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,7 @@
39873987
"NormalTitle": "基本功能",
39883988
"NormalIntro": "以「日」为基本单位,选择一段时间",
39893989
"BindValueTitle": "数据双向绑定",
3990-
"BindValueIntro": "点击确认按钮时间选择框值与文本框值一致",
3990+
"BindValueIntro": "点击确认按钮时间选择框值与文本框值一致,通过设置 <code>AutoClose=\"true\"</code> 实现自动关闭功能,通过设置 <code>ShowSelectedValue=\"true\"</code> 直接显示选中值",
39913991
"MaxMinValueTitle": "最大值和最小值",
39923992
"MaxMinValueIntro": "设置时间的取值范围",
39933993
"DisabledTitle": "禁用",

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.5.4</Version>
4+
<Version>9.5.5</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ private string? EndValueString
101101
[Parameter]
102102
public bool AutoCloseClickSideBar { get; set; }
103103

104+
/// <summary>
105+
/// Gets or sets whether to automatically close the popup after a date range is selected. Default is false.
106+
/// </summary>
107+
[Parameter]
108+
public bool AutoClose { get; set; }
109+
104110
/// <summary>
105111
/// Gets or sets whether show the selected value. Default is false.
106112
/// </summary>
@@ -509,7 +515,15 @@ private async Task UpdateValue(DateTime d)
509515
{
510516
await OnDateClick(d);
511517
}
512-
StateHasChanged();
518+
519+
if (AutoClose && SelectedValue.Start != DateTime.MinValue && SelectedValue.End != DateTime.MinValue)
520+
{
521+
await ClickConfirmButton();
522+
}
523+
else
524+
{
525+
StateHasChanged();
526+
}
513527
}
514528

515529
/// <summary>

test/UnitTest/Components/DateTimeRangeTest.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ public void StarEqualEnd_Ok()
7979
public async Task RangeValue_Ok()
8080
{
8181
var val = DateTime.Today;
82+
var confirmValue = new DateTimeRangeValue();
8283
var cut = Context.RenderComponent<DateTimeRange>(pb =>
8384
{
85+
pb.Add(a => a.OnConfirm, v =>
86+
{
87+
confirmValue = v;
88+
return Task.CompletedTask;
89+
});
90+
pb.Add(a => a.AutoClose, true);
8491
pb.Add(a => a.ShowSelectedValue, true);
8592
pb.Add(a => a.OnDateClick, d =>
8693
{
@@ -113,12 +120,9 @@ await cut.InvokeAsync(() =>
113120
input = inputs[1];
114121
Assert.Equal(start.ToString("yyyy-MM-dd"), input.GetAttribute("value"));
115122

116-
// confirm
117-
var confirm = cut.FindAll(".is-confirm")[cut.FindAll(".is-confirm").Count - 1];
118-
await cut.InvokeAsync(() =>
119-
{
120-
confirm.Click();
121-
});
123+
// 由于设置了 AutoClose 属性所以这里不需要点击确定按钮
124+
Assert.Equal(val, confirmValue.Start);
125+
Assert.Equal(start, confirmValue.End.Date);
122126

123127
var value = cut.Instance.Value;
124128
var startDate = DateTime.Today.AddDays(1 - DateTime.Today.Day).AddMonths(-1);

0 commit comments

Comments
 (0)