Skip to content

Commit e7ee959

Browse files
Merge pull request #130 from stavroskasidis/release/1.15
Release/1.15
2 parents 617ae9f + d0cfb16 commit e7ee959

File tree

7 files changed

+79
-5
lines changed

7 files changed

+79
-5
lines changed

BlazorContextMenu.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
.gitignore = .gitignore
1313
build-demo-app.bat = build-demo-app.bat
1414
build.bat = build.bat
15+
global.json = global.json
1516
LICENSE = LICENSE
1617
README.md = README.md
1718
EndProjectSection

BlazorContextMenu/BlazorContextMenu.csproj

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

BlazorContextMenu/Services/BlazorContextMenuService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using BlazorContextMenu.Services;
22
using Microsoft.JSInterop;
33
using System;
4-
using System.Collections.Generic;
5-
using System.Text;
64
using System.Threading.Tasks;
75

86
namespace BlazorContextMenu
@@ -34,6 +32,11 @@ public interface IBlazorContextMenuService
3432
/// <param name="data">Extra data that will be passed to menu events.</param>
3533
/// <returns></returns>
3634
Task ShowMenu(string id, int x, int y, object data);
35+
36+
/// <summary>Determines if a <see cref="ContextMenu" /> is already being shown.</summary>
37+
/// <param name="id">The id of the <see cref="ContextMenu"/>.</param>
38+
/// <returns>True if the <see cref="ContextMenu" /> is being shown, otherwise False.</returns>
39+
Task<bool> IsMenuShown(string id);
3740
}
3841

3942
public class BlazorContextMenuService : IBlazorContextMenuService
@@ -72,5 +75,7 @@ public Task ShowMenu(string id, int x, int y)
7275
{
7376
return ShowMenu(id, x, y, null);
7477
}
78+
79+
public async Task<bool> IsMenuShown(string id) => await _jSRuntime.InvokeAsync<bool>("blazorContextMenu.IsMenuShown", id);
7580
}
7681
}

BlazorContextMenu/wwwroot/blazorContextMenu.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ var blazorContextMenu = function (blazorContextMenu) {
205205
});
206206
}
207207

208+
blazorContextMenu.IsMenuShown = function (menuId) {
209+
var menuElement = document.getElementById(menuId);
210+
var instanceId = menuElement.dataset["instanceId"];
211+
var menu = openMenus.find(function (item) {
212+
return item.instanceId == instanceId;
213+
});
214+
return typeof(menu) != 'undefined' && menu != null;
215+
}
216+
208217
var subMenuTimeout = null;
209218
blazorContextMenu.OnMenuItemMouseOver = function (e, xOffset, currentItemElement) {
210219
if (closest(e.target, ".blazor-context-menu__wrapper") != closest(currentItemElement, ".blazor-context-menu__wrapper")) {

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ public class Startup
244244
</details>
245245
246246
## Release Notes
247-
<details open="open"><summary>1.14</summary>
247+
<details open="open"><summary>1.15</summary>
248+
249+
>- Add IsMenuShown to BlazorContextMenuService. Contributed by [Adam Ashton](https://github.com/adamashton).
250+
</details>
251+
252+
<details><summary>1.14</summary>
248253

249254
>- Fix for [#121](https://github.com/stavroskasidis/BlazorContextMenu/issues/121).
250255
</details>

TestApps/BlazorContextMenu.TestAppsCommon/CommonIndex.razor

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<p id="ignoreThis">Ignore this</p>
8181
</ContextMenuTrigger>
8282

83+
<ContextMenuTrigger MenuId="menu7" MouseButtonTrigger="MouseButtonTrigger.Left">
84+
<p id="menu7-test1-trigger">Left-click me (menu7)</p>
85+
</ContextMenuTrigger>
8386

8487

8588
<ContextMenu Id="menu1" Template="dark" OnAppearing="OnAppearingMenu1">
@@ -137,12 +140,22 @@
137140
<Item Id="menu6-item2" OnClick="OnClick"><ItemChild>Item 2</ItemChild></Item>
138141
</ContextMenu>
139142

143+
<ContextMenu Id="menu7" AutoHide="false">
144+
<Item Id="menu7-item1">Item 1</Item>
145+
<Item Id="menu7-item2">Item 2</Item>
146+
</ContextMenu>
147+
140148
<div>
141149
<button id="showMenuBtn" @onclick="ShowMenuBtnOnClick">Show menu1 in 300x300 using handler</button>
142150
<button id="showNoAutoCloseBtn" @onclick="ShowNoAutoCloseBtnOnClick">Show menu1 in 300x300 using handler</button>
143151
<button id="showAndHideMenuBtn" @onclick="ShowAndHideMenuBtnClick">Show menu1 in 300x300 using handler and hide after 2 seconds</button>
144152
</div>
145153

154+
<div>
155+
<button id="determineIfMenu7IsShownbtn" @onclick="DetermineIfMenu7IsShown">Determine if menu7 is shown</button>
156+
<p id="menu7-isShownResult">@IsMenu7Shown</p>
157+
</div>
158+
146159
<hr />
147160

148161
<ContextMenuTrigger MenuId="menu2">
@@ -172,12 +185,12 @@
172185
</div>
173186
</ContextMenuTrigger>
174187

175-
176188
<NavLink href="/TodoList">Go to Todo List</NavLink>
177189
<div id="app_loaded"></div>
178190

179191
@code{
180192
private bool menu1Autoclose = true;
193+
181194
protected async Task ShowMenuBtnOnClick()
182195
{
183196
await blazorContextMenuService.ShowMenu("menu1", 300, 300);
@@ -201,6 +214,14 @@
201214

202215
protected Animation Animation { get; set; }
203216

217+
protected string IsMenu7Shown { get; set; } = bool.FalseString;
218+
219+
protected async Task DetermineIfMenu7IsShown()
220+
{
221+
var isShown = await blazorContextMenuService.IsMenuShown("menu7");
222+
IsMenu7Shown = isShown.ToString();
223+
}
224+
204225
async Task FetchDataClick(ItemClickEventArgs e)
205226
{
206227
Console.WriteLine("Fetching");

Tests/BlazorContextMenu.TestsCommon/CommonTests/TestAppIndexTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,38 @@ public async Task Menu6_TriggerAndClickOutside_MenuCloses()
429429
var display = menuElement.GetCssValue("display");
430430
Assert.Equal(expectedDisplay, display);
431431
}
432+
433+
[Fact]
434+
public void Menu7_InitialState_MenuIsShownReturnsFalse()
435+
{
436+
//Arrange
437+
var expectedDisplay = bool.FalseString;
438+
439+
//Act
440+
var determineIfMenu7IsShownbtn = Browser.FindElement(By.Id("determineIfMenu7IsShownbtn"));
441+
determineIfMenu7IsShownbtn.Click();
442+
443+
//Assert
444+
var menuElement = Browser.FindElement(By.Id("menu7-isShownResult"));
445+
var display = menuElement.Text;
446+
Assert.Equal(expectedDisplay, display);
447+
}
448+
449+
[Fact]
450+
public async Task Menu7_TriggerMenu_MenuIsShownReturnsTrue()
451+
{
452+
//Arrange
453+
var expectedDisplay = bool.TrueString;
454+
455+
//Act
456+
await OpenContextMenuAt("menu7-test1-trigger", MouseButtonTrigger.Left);
457+
var determineIfMenu7IsShownbtn = Browser.FindElement(By.Id("determineIfMenu7IsShownbtn"));
458+
determineIfMenu7IsShownbtn.Click();
459+
460+
//Assert
461+
var menuElement = Browser.FindElement(By.Id("menu7-isShownResult"));
462+
var display = menuElement.Text;
463+
Assert.Equal(expectedDisplay, display);
464+
}
432465
}
433466
}

0 commit comments

Comments
 (0)