Skip to content

Commit 89a1bb1

Browse files
committed
feat: 增加右键支持
1 parent b5fbcfd commit 89a1bb1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/BootstrapBlazor/Components/Tab/Tab.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ else
166166

167167
RenderFragment RenderHeaderItem(TabItem item) =>
168168
@<div @key="@item" class="@GetItemWrapClassString(item)" draggable="@DraggableString">
169-
<a href="@item.Url" role="tab" tabindex="-1" class="@GetClassString(item)" @onclick="@(() => OnClickTabItem(item))" @onclick:preventDefault="@(!ClickTabToNavigation)">
169+
<a href="@item.Url" role="tab" tabindex="-1" class="@GetClassString(item)"
170+
@oncontextmenu="e => OnContextMenu(e, item)" @oncontextmenu:preventDefault="IsPreventDefault"
171+
@onclick="@(() => OnClickTabItem(item))" @onclick:preventDefault="@(!ClickTabToNavigation)">
170172
@RenderHeaderItemContent(item)
171173
</a>
172174
@if (TabStyle == TabStyle.Chrome)

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.AspNetCore.Components.Web;
67
using Microsoft.Extensions.Localization;
78
using System.Collections.Concurrent;
89
using System.Reflection;
@@ -370,6 +371,9 @@ public partial class Tab : IHandlerException
370371
[Inject, NotNull]
371372
private DialogService? DialogService { get; set; }
372373

374+
[CascadingParameter]
375+
private ContextMenuZone? ContextMenuZone { get; set; }
376+
373377
private ConcurrentDictionary<TabItem, bool> LazyTabCache { get; } = new();
374378

375379
private bool HandlerNavigation { get; set; }
@@ -382,6 +386,8 @@ public partial class Tab : IHandlerException
382386

383387
private readonly ConcurrentDictionary<TabItem, TabItemContent> _cache = [];
384388

389+
private bool IsPreventDefault => ContextMenuZone != null;
390+
385391
/// <summary>
386392
/// <inheritdoc/>
387393
/// </summary>
@@ -965,4 +971,12 @@ protected override async ValueTask DisposeAsync(bool disposing)
965971
ErrorLogger?.UnRegister(this);
966972
}
967973
}
974+
975+
private async Task OnContextMenu(MouseEventArgs e, TabItem item)
976+
{
977+
if (ContextMenuZone != null)
978+
{
979+
await ContextMenuZone.OnContextMenu(e, item);
980+
}
981+
}
968982
}

0 commit comments

Comments
 (0)