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 diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs index a44e9648732..97aa84b091e 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs @@ -45,6 +45,13 @@ public class ContextMenuTrigger : BootstrapComponentBase [Parameter] public int? OnTouchDelay { get; set; } + /// + /// 标记滚动时上下文菜单是否应不可见。默认值为 false。 + /// Flags whether the context menu should be invisible while scrolling. Default is false. + /// + [Parameter] + public bool IsInvisibleWhenTouchMove { get; set; } + [Inject, NotNull] private IOptionsMonitor? Options { get; set; } @@ -73,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); builder.CloseElement(); @@ -97,6 +108,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) @@ -133,6 +146,14 @@ private async Task OnTouchStart(TouchEventArgs e) } } + private void OnTouchMove() + { + if (IsInvisibleWhenTouchMove) + { + IsTouchStarted = false; + } + } + private void OnTouchEnd() { IsTouchStarted = false; diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index b91cd791c48..b8d8fe03ae2 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"); @@ -105,6 +106,9 @@ public async Task ContextMenu_Ok() await Task.Delay(500); row.TouchEnd(); Assert.True(clicked); + + // 触发 TouchMove 事件 + row.TouchMove(); } [Theory]