From 9a427c8e0833b39db8687e0fa7b3c58ac14d07b2 Mon Sep 17 00:00:00 2001 From: peereflits Date: Mon, 30 Mar 2026 19:32:41 +0200 Subject: [PATCH 01/10] Fix: context menu should be invisible while scrolling #7821 This is a prposed solution, based on logical deduction. It is hard for me to test this. --- .../ContextMenu/ContextMenuTrigger.cs | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index a44e9648732..c82e70d1ca1 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -45,6 +45,14 @@ public class ContextMenuTrigger : BootstrapComponentBase [Parameter] public int? OnTouchDelay { get; set; } + /// + /// 标记滚动时上下文菜单是否应不可见。默认值为 + /// Flags whether the context menu should be invisible while scrolling. Default is . + /// + [Parameter] + public bool IsInvisibleOnTouchMove { get; set; } + + [Inject, NotNull] private IOptionsMonitor? Options { get; set; } @@ -67,14 +75,16 @@ protected override void OnParametersSet() /// protected override void BuildRenderTree(RenderTreeBuilder builder) { - builder.OpenElement(0, WrapperTag); - builder.AddMultipleAttributes(10, AdditionalAttributes); - builder.AddAttribute(20, "class", ClassString); - builder.AddAttribute(30, "oncontextmenu", EventCallback.Factory.Create(this, OnContextMenu)); - builder.AddAttribute(35, "ontouchstart", EventCallback.Factory.Create(this, OnTouchStart)); - builder.AddAttribute(36, "ontouchend", EventCallback.Factory.Create(this, OnTouchEnd)); - builder.AddEventPreventDefaultAttribute(40, "oncontextmenu", true); - builder.AddContent(50, ChildContent); + int i = 0; + builder.OpenElement(i++, WrapperTag); + builder.AddMultipleAttributes(i++, AdditionalAttributes); + builder.AddAttribute(i++, "class", ClassString); + builder.AddAttribute(i++, "oncontextmenu", EventCallback.Factory.Create(this, OnContextMenu)); + builder.AddAttribute(i++, "ontouchstart", EventCallback.Factory.Create(this, OnTouchStart)); + builder.AddAttribute(i++, "ontouchmove", EventCallback.Factory.Create(this, OnTouchMove)); + builder.AddAttribute(i++, "ontouchend", EventCallback.Factory.Create(this, OnTouchEnd)); + builder.AddEventPreventDefaultAttribute(i++, "oncontextmenu", true); + builder.AddContent(i, ChildContent); builder.CloseElement(); } @@ -133,6 +143,15 @@ private async Task OnTouchStart(TouchEventArgs e) } } + private void OnTouchMove() + { + if (IsInvisibleOnTouchMove) + { + IsBusy = false; + IsTouchStarted = false; + } + } + private void OnTouchEnd() { IsTouchStarted = false; From b8769ff33a5a21f622f18551d758bc3de8395bdb Mon Sep 17 00:00:00 2001 From: peereflits Date: Mon, 30 Mar 2026 19:52:24 +0200 Subject: [PATCH 02/10] Fix: resolved issues on https://github.com/dotnetcore/BootstrapBlazor/pull/7822#pullrequestreview-4032254122 #7821 --- .../Components/ContextMenu/ContextMenuTrigger.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index c82e70d1ca1..5f35722ff22 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -52,7 +52,6 @@ public class ContextMenuTrigger : BootstrapComponentBase [Parameter] public bool IsInvisibleOnTouchMove { get; set; } - [Inject, NotNull] private IOptionsMonitor? Options { get; set; } @@ -143,16 +142,15 @@ private async Task OnTouchStart(TouchEventArgs e) } } - private void OnTouchMove() + private void OnTouchMove(TouchEventArgs e) { if (IsInvisibleOnTouchMove) { - IsBusy = false; IsTouchStarted = false; } } - private void OnTouchEnd() + private void OnTouchEnd(TouchEventArgs e) { IsTouchStarted = false; } From 7999e33e48a3908a7839a083eb49359ee3418061 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:19:32 +0800 Subject: [PATCH 03/10] refactor: update parameter to IsInvisibleWhenTouchMove --- .../Components/ContextMenu/ContextMenuTrigger.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index 5f35722ff22..28615228bc6 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -46,11 +46,11 @@ public class ContextMenuTrigger : BootstrapComponentBase public int? OnTouchDelay { get; set; } /// - /// 标记滚动时上下文菜单是否应不可见。默认值为 - /// Flags whether the context menu should be invisible while scrolling. Default is . + /// 标记滚动时上下文菜单是否应不可见。默认值为 false。 + /// Flags whether the context menu should be invisible while scrolling. Default is false. /// [Parameter] - public bool IsInvisibleOnTouchMove { get; set; } + public bool IsInvisibleWhenTouchMove { get; set; } [Inject, NotNull] private IOptionsMonitor? Options { get; set; } @@ -144,7 +144,7 @@ private async Task OnTouchStart(TouchEventArgs e) private void OnTouchMove(TouchEventArgs e) { - if (IsInvisibleOnTouchMove) + if (IsInvisibleWhenTouchMove) { IsTouchStarted = false; } From 9c6cdabff43b38d57b26b6d7d7411b1a1b472cc5 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:20:24 +0800 Subject: [PATCH 04/10] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=98=B2=E6=AD=A2=E8=A2=AB=E8=A3=81=E5=89=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/ContextMenu/ContextMenuTrigger.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index 28615228bc6..d1b35870312 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -106,6 +106,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) /// private bool IsBusy { get; set; } + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(TouchEventArgs))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(TouchPoint))] private async Task OnTouchStart(TouchEventArgs e) { if (!IsBusy) From 78e87dbf777b2bdb3c7f42724b59b21fb6a3246b Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:20:43 +0800 Subject: [PATCH 05/10] =?UTF-8?q?revert:=20=E4=BB=A3=E7=A0=81=E6=92=A4?= =?UTF-8?q?=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContextMenu/ContextMenuTrigger.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index d1b35870312..780ba504f09 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -74,17 +74,14 @@ protected override void OnParametersSet() /// protected override void BuildRenderTree(RenderTreeBuilder builder) { - int i = 0; - builder.OpenElement(i++, WrapperTag); - builder.AddMultipleAttributes(i++, AdditionalAttributes); - builder.AddAttribute(i++, "class", ClassString); - builder.AddAttribute(i++, "oncontextmenu", EventCallback.Factory.Create(this, OnContextMenu)); - builder.AddAttribute(i++, "ontouchstart", EventCallback.Factory.Create(this, OnTouchStart)); - builder.AddAttribute(i++, "ontouchmove", EventCallback.Factory.Create(this, OnTouchMove)); - builder.AddAttribute(i++, "ontouchend", EventCallback.Factory.Create(this, OnTouchEnd)); - builder.AddEventPreventDefaultAttribute(i++, "oncontextmenu", true); - builder.AddContent(i, ChildContent); - builder.CloseElement(); + builder.OpenElement(0, WrapperTag); + builder.AddMultipleAttributes(10, AdditionalAttributes); + builder.AddAttribute(20, "class", ClassString); + builder.AddAttribute(30, "oncontextmenu", EventCallback.Factory.Create(this, OnContextMenu)); + builder.AddAttribute(35, "ontouchstart", EventCallback.Factory.Create(this, OnTouchStart)); + builder.AddAttribute(36, "ontouchend", EventCallback.Factory.Create(this, OnTouchEnd)); + builder.AddEventPreventDefaultAttribute(40, "oncontextmenu", true); + builder.AddContent(50, ChildContent); } /// @@ -144,7 +141,7 @@ private async Task OnTouchStart(TouchEventArgs e) } } - private void OnTouchMove(TouchEventArgs e) + private void OnTouchMove() { if (IsInvisibleWhenTouchMove) { @@ -152,7 +149,7 @@ private void OnTouchMove(TouchEventArgs e) } } - private void OnTouchEnd(TouchEventArgs e) + private void OnTouchEnd() { IsTouchStarted = false; } From 18d309ad3abfc7e81af32d7c43ff05f758301b42 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:21:02 +0800 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20ontouchmove?= =?UTF-8?q?=20=E4=BA=8B=E4=BB=B6=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/ContextMenu/ContextMenuTrigger.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index 780ba504f09..f682bc1a611 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -80,6 +80,10 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddAttribute(30, "oncontextmenu", EventCallback.Factory.Create(this, OnContextMenu)); builder.AddAttribute(35, "ontouchstart", EventCallback.Factory.Create(this, OnTouchStart)); builder.AddAttribute(36, "ontouchend", EventCallback.Factory.Create(this, OnTouchEnd)); + if (IsInvisibleWhenTouchMove) + { + builder.AddAttribute(37, "ontouchmove", EventCallback.Factory.Create(this, OnTouchMove)); + } builder.AddEventPreventDefaultAttribute(40, "oncontextmenu", true); builder.AddContent(50, ChildContent); } From 51dca4b03d72895500efc02908971e4473df0e20 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:23:31 +0800 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20close=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index f682bc1a611..97aa84b091e 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -86,6 +86,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) } builder.AddEventPreventDefaultAttribute(40, "oncontextmenu", true); builder.AddContent(50, ChildContent); + builder.CloseElement(); } /// From 625537a3969d5d0547f332652ccd938e97b59f15 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:37:34 +0800 Subject: [PATCH 08/10] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=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/ContextMenuTest.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index b91cd791c48..af09ba5fdf0 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -26,6 +26,7 @@ public async Task ContextMenu_Ok() { pb.Add(a => a.WrapperTag, "div"); pb.Add(a => a.ContextItem, foo); + pb.Add(a => a.IsInvisibleWhenTouchMove, true); pb.AddChildContent(pb => { pb.OpenElement(0, "div"); @@ -99,12 +100,12 @@ public async Task ContextMenu_Ok() item.Click(); Assert.True(menuCallback); - // 测试 Touch 事件 - TriggerTouchStart(row); - await Task.Delay(500); row.TouchEnd(); Assert.True(clicked); + + // 触发 TouchMove 事件 + row.TouchMove(); } [Theory] From e613d5e4dd7b9af3963ae23c6a095d755c13a53a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:38:05 +0800 Subject: [PATCH 09/10] chore: bump version 10.5.0 --- 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 e4840c5568e..6ce5e82c256 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 10.5.0-beta04 + 10.5.0 From 53637c6735ffa721f863323f92ed32d6afc70cf9 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 31 Mar 2026 10:39:35 +0800 Subject: [PATCH 10/10] =?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/ContextMenuTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index af09ba5fdf0..b8d8fe03ae2 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -100,6 +100,9 @@ public async Task ContextMenu_Ok() item.Click(); Assert.True(menuCallback); + // 测试 Touch 事件 + TriggerTouchStart(row); + await Task.Delay(500); row.TouchEnd(); Assert.True(clicked);