stavroskasidis / BlazorContextMenu

A context menu component for Blazor !
MIT License
532 stars 58 forks source link

Add IsMenuShown to BlazorContextMenuService #128

Closed adamashton closed 1 year ago

adamashton commented 1 year ago

Overview

This came about because I have a button that shows the Menu via a button click.

<button @onclick="ToggleMenu">Show Menu</button>

with

private async Task ToggleMenu()
{
  if (menuIsShown)
  {
      await BlazorContextMenuService.HideMenu("menu");
  }
  else
  {
      await BlazorContextMenuService.ShowMenu("menu", (int) mouseEventArgs.ClientX, (int) mouseEventArgs.ClientY);
  }
  menuIsShown = !menuIsShown;
}  

My local variable menuIsShown cannot be used because the Menu is set to AutoHide. I need another way of determining if the menu is shown. E.g.,

if (BlazorContextMenuService.IsMenuShown("menu"))
{
    await BlazorContextMenuService.HideMenu("menu");
}
else
{
    await BlazorContextMenuService.ShowMenu("menu", (int) mouseEventArgs.ClientX, mouseEventArgs.ClientY);
}

Tests

I could not get the tests to run but I have attempted to write some.

stavroskasidis commented 1 year ago

Wow, thank you for contributing. I will merge and push a new version

yeganehaym commented 5 months ago

the last version on nuget doesnt have any methos in "blazorContextMenuService" ? i had to install 1.16