Skip to content
Merged
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.5.0-beta04</Version>
<Version>10.5.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public class ContextMenuTrigger : BootstrapComponentBase
[Parameter]
public int? OnTouchDelay { get; set; }

/// <summary>
/// <para lang="zh">标记滚动时上下文菜单是否应不可见。默认值为 false。</para>
/// <para lang="en">Flags whether the context menu should be invisible while scrolling. Default is false.</para>
/// </summary>
[Parameter]
public bool IsInvisibleWhenTouchMove { get; set; }

[Inject, NotNull]
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }

Expand Down Expand Up @@ -73,6 +80,10 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(30, "oncontextmenu", EventCallback.Factory.Create<MouseEventArgs>(this, OnContextMenu));
builder.AddAttribute(35, "ontouchstart", EventCallback.Factory.Create<TouchEventArgs>(this, OnTouchStart));
builder.AddAttribute(36, "ontouchend", EventCallback.Factory.Create<TouchEventArgs>(this, OnTouchEnd));
if (IsInvisibleWhenTouchMove)
{
builder.AddAttribute(37, "ontouchmove", EventCallback.Factory.Create<TouchEventArgs>(this, OnTouchMove));
}
builder.AddEventPreventDefaultAttribute(40, "oncontextmenu", true);
builder.AddContent(50, ChildContent);
builder.CloseElement();
Expand All @@ -97,6 +108,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
/// </summary>
private bool IsBusy { get; set; }

[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(TouchEventArgs))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(TouchPoint))]
private async Task OnTouchStart(TouchEventArgs e)
{
if (!IsBusy)
Expand Down Expand Up @@ -133,6 +146,14 @@ private async Task OnTouchStart(TouchEventArgs e)
}
}

private void OnTouchMove()
{
if (IsInvisibleWhenTouchMove)
{
IsTouchStarted = false;
}
}

private void OnTouchEnd()
{
IsTouchStarted = false;
Expand Down
4 changes: 4 additions & 0 deletions test/UnitTest/Components/ContextMenuTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -105,6 +106,9 @@ public async Task ContextMenu_Ok()
await Task.Delay(500);
row.TouchEnd();
Assert.True(clicked);

// 触发 TouchMove 事件
row.TouchMove();
}

[Theory]
Expand Down
Loading