Skip to content

Commit e8eb159

Browse files
2 parents 8bf31af + 7f8a3ab commit e8eb159

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

BlazorContextMenu/BlazorContextMenu.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Copyright />
1818
<PackageTags>blazor blazor-component blazor-context-menu context-menu contextmenu menu blazor-menu blazorcontextmenu razor razor-components razorcomponents</PackageTags>
1919
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
20-
<Version>1.7.0</Version>
20+
<Version>1.9.0</Version>
2121
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
2222
<Product>Blazor.ContextMenu</Product>
2323
</PropertyGroup>

BlazorContextMenu/Components/ContextMenu.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@inherits ContextMenuBase
22
@namespace BlazorContextMenu
33

4-
<div @attributes="@Attributes" class="@($"{BaseClass} {ClassCalc} {DisplayClassCalc}")" id="@Id" style="@($"left:{X}px;top:{Y}px;")" data-autohide="@AutoHide.ToString().ToLower()">
4+
<div @attributes="@Attributes" class="@($"{BaseClass} {ClassCalc} {DisplayClassCalc}")" id="@Id" style="@($"left:{X}px;top:{Y}px;z-index:{ZIndex};")" data-autohide="@AutoHide.ToString().ToLower()">
55
@if (IsShowing)
66
{
77
<ul class="@ListClassCalc">
@@ -23,4 +23,4 @@
2323
@code{
2424
[Parameter]
2525
public RenderFragment<MenuRenderingContext> ChildContent { get; set; }
26-
}
26+
}

BlazorContextMenu/Components/ContextMenuBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public abstract class ContextMenuBase : MenuTreeComponent
108108
[Parameter]
109109
public bool AutoHide { get; set; } = true;
110110

111+
/// <summary>
112+
/// Set CSS z-index for overlapping other html elements. Default: 1000
113+
/// </summary>
114+
[Parameter]
115+
public int ZIndex { get; set; } = 1000;
116+
111117
[CascadingParameter(Name = "CascadingAnimation")]
112118
protected Animation? CascadingAnimation { get; set; }
113119

BlazorContextMenu/Components/ContextMenuTrigger.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
3333

3434
if (MouseButtonTrigger == MouseButtonTrigger.Left || MouseButtonTrigger == MouseButtonTrigger.Both)
3535
{
36-
builder.AddAttribute(2, "onclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}');");
36+
builder.AddAttribute(2, "onclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
3737
}
3838

3939
if (MouseButtonTrigger == MouseButtonTrigger.Right || MouseButtonTrigger == MouseButtonTrigger.Both)
4040
{
41-
builder.AddAttribute(3, "oncontextmenu", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}');");
41+
builder.AddAttribute(3, "oncontextmenu", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
4242
}
4343

4444
if (MouseButtonTrigger == MouseButtonTrigger.DoubleClick)
4545
{
46-
builder.AddAttribute(4, "ondblclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}');");
46+
builder.AddAttribute(4, "ondblclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
4747
}
4848

4949
if (!string.IsNullOrWhiteSpace(CssClass))
@@ -103,6 +103,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
103103
[Parameter]
104104
public object Data { get; set; }
105105

106+
/// <summary>
107+
/// Set to false if you do not want the click event to stop propagating. Default: true
108+
/// </summary>
109+
[Parameter]
110+
public bool StopPropagation { get; set; } = true;
111+
106112
[Parameter]
107113
public RenderFragment ChildContent { get; set; }
108114

BlazorContextMenu/wwwroot/blazorContextMenu.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ var blazorContextMenu = function (blazorContextMenu) {
111111
showMenuCommon(menu, menuId, x, y, null, null);
112112
}
113113

114-
blazorContextMenu.OnContextMenu = function (e, menuId) {
114+
blazorContextMenu.OnContextMenu = function (e, menuId, stopPropagation) {
115115
//openingMenu = true;
116116
var menu = document.getElementById(menuId);
117117
if (!menu) throw new Error("No context menu with id '" + menuId + "' was found");
118118
addToOpenMenus(menu,menuId, e.target);
119119
var triggerDotnetRef = JSON.parse(e.currentTarget.dataset["dotnetref"]);
120120
showMenuCommon(menu, menuId, e.x, e.y, e.target, triggerDotnetRef);
121121
e.preventDefault();
122-
e.stopPropagation();
122+
if (stopPropagation) {
123+
e.stopPropagation();
124+
}
123125
return false;
124126
};
125127

@@ -157,7 +159,17 @@ var blazorContextMenu = function (blazorContextMenu) {
157159
}
158160
});
159161

160-
162+
window.addEventListener('resize', function () {
163+
if (openMenus.length > 0) {
164+
for (var i = 0; i < openMenus.length; i++) {
165+
var currentMenu = openMenus[i];
166+
var menuElement = document.getElementById(currentMenu.id);
167+
if (menuElement && menuElement.dataset["autohide"] == "true") {
168+
blazorContextMenu.Hide(currentMenu.id);
169+
}
170+
}
171+
}
172+
}, true);
161173
};
162174

163175

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,18 @@ public class Startup
239239
</details>
240240
241241
## Release Notes
242-
<details open="open"><summary>1.7</summary>
242+
<details open="open"><summary>1.9</summary>
243+
244+
>- Added `ZIndex` support in `ContextMenu` component (default `1000`). Contributed by [grishat](https://github.com/grishat).
245+
>- Added autohide support in `ContextMenu` when window is resizing. Contributed by [grishat](https://github.com/grishat).
246+
</details>
247+
248+
<details><summary>1.8</summary>
249+
250+
>- Added `StopPropagation` parameter on `ContextMenuTrigger` (default `true`).
251+
</details>
252+
253+
<details><summary>1.7</summary>
243254

244255
>- Fix for [#81](https://github.com/stavroskasidis/BlazorContextMenu/issues/81).
245256
</details>

0 commit comments

Comments
 (0)