From f7ed7abb98f6e00406d7776b89546433cc80ad5d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:51:44 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20AutoClose=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DateTimeRange/DateTimeRange.razor.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs b/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs index 60bc1b681c1..0650dd2624d 100644 --- a/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs +++ b/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs @@ -101,6 +101,12 @@ private string? EndValueString [Parameter] public bool AutoCloseClickSideBar { get; set; } + /// + /// Gets or sets whether to auto close the popup when the user selected range value. Default is false. + /// + [Parameter] + public bool AutoClose { get; set; } + /// /// Gets or sets whether show the selected value. Default is false. /// @@ -509,7 +515,15 @@ private async Task UpdateValue(DateTime d) { await OnDateClick(d); } - StateHasChanged(); + + if (AutoClose && SelectedValue.Start != DateTime.MinValue && SelectedValue.End != DateTime.MinValue) + { + await ClickConfirmButton(); + } + else + { + StateHasChanged(); + } } /// From e876e9f1ef7f04b7c75fcc7b6540ca79636b55c0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:52:10 +0800 Subject: [PATCH 2/6] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/DateTimeRanges.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/DateTimeRanges.razor b/src/BootstrapBlazor.Server/Components/Samples/DateTimeRanges.razor index 874adac8e2f..e502a5fb11d 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/DateTimeRanges.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/DateTimeRanges.razor @@ -39,7 +39,7 @@ + ShowSelectedValue="true" AutoClose="true">
From 7a74ea9b5c4b4193eefccf72f53130be2ca3223b Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:52:17 +0800 Subject: [PATCH 3/6] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DateTimeRangeTest.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/UnitTest/Components/DateTimeRangeTest.cs b/test/UnitTest/Components/DateTimeRangeTest.cs index 4c25d8250e7..c78c6ef011d 100644 --- a/test/UnitTest/Components/DateTimeRangeTest.cs +++ b/test/UnitTest/Components/DateTimeRangeTest.cs @@ -79,8 +79,15 @@ public void StarEqualEnd_Ok() public async Task RangeValue_Ok() { var val = DateTime.Today; + var confirmValue = new DateTimeRangeValue(); var cut = Context.RenderComponent(pb => { + pb.Add(a => a.OnConfirm, v => + { + confirmValue = v; + return Task.CompletedTask; + }); + pb.Add(a => a.AutoClose, true); pb.Add(a => a.ShowSelectedValue, true); pb.Add(a => a.OnDateClick, d => { @@ -113,12 +120,9 @@ await cut.InvokeAsync(() => input = inputs[1]; Assert.Equal(start.ToString("yyyy-MM-dd"), input.GetAttribute("value")); - // confirm - var confirm = cut.FindAll(".is-confirm")[cut.FindAll(".is-confirm").Count - 1]; - await cut.InvokeAsync(() => - { - confirm.Click(); - }); + // 由于设置了 AutoClose 属性所以这里不需要点击确定按钮 + Assert.Equal(val, confirmValue.Start); + Assert.Equal(start, confirmValue.End.Date); var value = cut.Instance.Value; var startDate = DateTime.Today.AddDays(1 - DateTime.Today.Day).AddMonths(-1); From dc95acb3108b1f75ddda70809aeab5976cd50301 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:55:57 +0800 Subject: [PATCH 4/6] =?UTF-8?q?doc:=20=E5=A2=9E=E5=8A=A0=20AutoClose=20?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Locales/en-US.json | 2 +- src/BootstrapBlazor.Server/Locales/zh-CN.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 654363a9b31..e5a49384fea 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -3987,7 +3987,7 @@ "NormalTitle": "Basic skills", "NormalIntro": "Take 'day' as the basic unit, select a period of time", "BindValueTitle": "Data two-way binding", - "BindValueIntro": "Click the confirm button, the time selection box value is the same as the text box value", + "BindValueIntro": "Click the confirm button, the time selection box value is the same as the text box value. Enable auto-close by setting AutoClose=\"true\". Directly display the selected value by setting ShowSelectedValue=\"true\"", "MaxMinValueTitle": "Max and Min", "MaxMinValueIntro": "set time range", "DisabledTitle": "Disabled", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 5d8b77edbdb..b686cf3211b 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -3987,7 +3987,7 @@ "NormalTitle": "基本功能", "NormalIntro": "以「日」为基本单位,选择一段时间", "BindValueTitle": "数据双向绑定", - "BindValueIntro": "点击确认按钮时间选择框值与文本框值一致", + "BindValueIntro": "点击确认按钮时间选择框值与文本框值一致,通过设置 AutoClose=\"true\" 实现自动关闭功能,通过设置 ShowSelectedValue=\"true\" 直接显示选中值", "MaxMinValueTitle": "最大值和最小值", "MaxMinValueIntro": "设置时间的取值范围", "DisabledTitle": "禁用", From ae095973acfc7907d7b4b634a33807e5af3f9b2e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:56:28 +0800 Subject: [PATCH 5/6] chore: bump version 9.5.5 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index f32ea84df8f..bafc8bb9971 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.5.4 + 9.5.5 From b78718636e520bf291bec5509ed36d92007598aa Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 9 Apr 2025 12:59:42 +0800 Subject: [PATCH 6/6] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/DateTimeRange/DateTimeRange.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs b/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs index 0650dd2624d..7a3e6ed4d4f 100644 --- a/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs +++ b/src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs @@ -102,7 +102,7 @@ private string? EndValueString public bool AutoCloseClickSideBar { get; set; } /// - /// Gets or sets whether to auto close the popup when the user selected range value. Default is false. + /// Gets or sets whether to automatically close the popup after a date range is selected. Default is false. /// [Parameter] public bool AutoClose { get; set; }