Skip to content

Commit 7a97370

Browse files
Merge pull request #99 from stavroskasidis/release/1.10
Release/1.10
2 parents 7a816d5 + 1203b85 commit 7a97370

File tree

18 files changed

+111
-25
lines changed

18 files changed

+111
-25
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.9.0</Version>
20+
<Version>1.10.0</Version>
2121
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
2222
<Product>Blazor.ContextMenu</Product>
2323
</PropertyGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace BlazorContextMenu
6+
{
7+
public enum AutoHideEvent
8+
{
9+
MouseDown, //default
10+
MouseUp
11+
}
12+
}

BlazorContextMenu/Components/ContextMenu.razor

Lines changed: 1 addition & 1 deletion
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;z-index:{ZIndex};")" 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()" data-autohideevent="@AutoHideEvent.ToString().ToLower()">
55
@if (IsShowing)
66
{
77
<ul class="@ListClassCalc">

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 to AutoHideEvent.MouseUp if you want it to close the menu on the MouseUp event. Default: AutoHideEvent.MouseDown
113+
/// </summary>
114+
[Parameter]
115+
public AutoHideEvent AutoHideEvent { get; set; } = AutoHideEvent.MouseDown;
116+
111117
/// <summary>
112118
/// Set CSS z-index for overlapping other html elements. Default: 1000
113119
/// </summary>

BlazorContextMenu/wwwroot/blazorContextMenu.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,19 @@ var blazorContextMenu = function (blazorContextMenu) {
144144

145145
blazorContextMenu.Init = function () {
146146
document.addEventListener("mouseup", function (e) {
147+
handleAutoHideEvent(e, "mouseup");
148+
});
149+
150+
document.addEventListener("mousedown", function (e) {
151+
handleAutoHideEvent(e, "mousedown");
152+
});
153+
154+
function handleAutoHideEvent(e, autoHideEvent) {
147155
if (openMenus.length > 0) {
148156
for (var i = 0; i < openMenus.length; i++) {
149157
var currentMenu = openMenus[i];
150158
var menuElement = document.getElementById(currentMenu.id);
151-
if (menuElement && menuElement.dataset["autohide"] == "true") {
159+
if (menuElement && menuElement.dataset["autohide"] == "true" && menuElement.dataset["autohideevent"] == autoHideEvent) {
152160
var clickedInsideMenu = menuElement.contains(e.target);
153161
if (!clickedInsideMenu) {
154162
blazorContextMenu.Hide(currentMenu.id);
@@ -157,7 +165,7 @@ var blazorContextMenu = function (blazorContextMenu) {
157165

158166
}
159167
}
160-
});
168+
}
161169

162170
window.addEventListener('resize', function () {
163171
if (openMenus.length > 0) {

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ public class Startup
190190

191191
## ⚠️ Breaking changes ⚠️
192192

193-
<details open="open"><summary>Upgrading from 0.19 to 0.20</summary>
193+
<details open="open"><summary>Upgrading from 1.9.0 to 1.10.0</summary>
194+
195+
>- The default auto-hide event is now on "mousedown". If you want the old behaviour, you can use the new `AutoHideEvent` parameter on the `ContextMenu` component to change it back to "mouseup".
196+
</details>
197+
198+
<details><summary>Upgrading from 0.19 to 0.20</summary>
194199

195200
>- Replaced the `ContextMenuTriggerId` in events with the reference to the actual `ContextMenuTrigger`
196201
</details>
@@ -239,7 +244,12 @@ public class Startup
239244
</details>
240245
241246
## Release Notes
242-
<details open="open"><summary>1.9</summary>
247+
<details open="open"><summary>1.10</summary>
248+
249+
>- Changed default auto hide event to "mousedown". Old behaviour ("mouseup") is available by using the `AutoHideEvent` parameter on the `ContextMenu` component. Contributed by [KristofferStrube](https://github.com/KristofferStrube).
250+
</details>
251+
252+
<details><summary>1.9</summary>
243253

244254
>- Added `ZIndex` support in `ContextMenu` component (default `1000`). Contributed by [grishat](https://github.com/grishat).
245255
>- Added autohide support in `ContextMenu` when window is resizing. Contributed by [grishat](https://github.com/grishat).

TestApps/BlazorContextMenu.TestAppsCommon/CommonIndex.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
<p id="test12-trigger">Right-Click me (menu4 unhideable)</p>
6868
</ContextMenuTrigger>
6969

70+
<ContextMenuTrigger MenuId="menu5">
71+
<p id="test13-trigger">Right-Click me (menu5 hides on mouseup)</p>
72+
</ContextMenuTrigger>
73+
7074

7175
<ContextMenu Id="menu1" Template="dark" OnAppearing="OnAppearingMenu1">
7276
<Item Id="menu1-item1" OnClick="FetchDataClick">Fetch Data</Item>
@@ -113,6 +117,11 @@
113117
<Item Id="menu4-item2" OnClick="OnClick">Item 2</Item>
114118
</ContextMenu>
115119

120+
<ContextMenu Id="menu5" AutoHideEvent="AutoHideEvent.MouseUp" >
121+
<Item Id="menu4-item1" OnClick="OnClick">Item 1</Item>
122+
<Item Id="menu4-item2" OnClick="OnClick">Item 2</Item>
123+
</ContextMenu>
124+
116125
<div>
117126
<button id="showMenuBtn" @onclick="ShowMenuBtnOnClick">Show menu1 in 300x300 using handler</button>
118127
<button id="showNoAutoCloseBtn" @onclick="ShowNoAutoCloseBtnOnClick">Show menu1 in 300x300 using handler</button>
@@ -150,6 +159,8 @@
150159

151160

152161
<NavLink href="/TodoList">Go to Todo List</NavLink>
162+
<div id="app_loaded"></div>
163+
153164
@code{
154165
private bool menu1Autoclose = true;
155166
protected async Task ShowMenuBtnOnClick()

TestApps/BlazorContextMenu.TestAppsCommon/CommonTodoList.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</ContextMenu>
3434

3535
<button id="manualShowBtn" @onclick="BtnClick">Show menu for first item</button>
36+
<div id="app_loaded"></div>
3637

3738
@code{
3839

TestApps/BlazorContextMenu.TestAppsCommon/wwwroot/interop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929

3030
TestApp_AppLoaded = function () {
3131
var appLoadedElement = document.createElement("div");
32-
appLoadedElement.id = "app-loaded";
32+
appLoadedElement.id = "app_loaded";
3333
document.body.appendChild(appLoadedElement);
3434
}

TestApps/BlazorTestApp/BlazorContextMenu.BlazorTestApp.Client/App.razor

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212

1313

14-
@inject IJSRuntime jsRuntime
14+
@*@inject IJSRuntime jsRuntime
1515
@code{
1616
protected override async Task OnAfterRenderAsync(bool firstRender)
1717
{
18-
await jsRuntime.InvokeAsync<object>("TestApp_AppLoaded");
18+
if (firstRender)
19+
{
20+
await jsRuntime.InvokeVoidAsync("TestApp_AppLoaded");
21+
}
1922
}
20-
}
23+
}*@

0 commit comments

Comments
 (0)