stavroskasidis / BlazorContextMenu

A context menu component for Blazor !

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Cannot read properties of undefined (reading 'removeEventListener')" after closing menu

dantronik-bugreporting opened this issue · comments

Describe the bug
A second after closing the menu, I'm getting this error in the JS console:

blazorContextMenu.js:256 Uncaught TypeError: Cannot read properties of undefined (reading 'removeEventListener')
    at HTMLLIElement.closeSubMenus (blazorContextMenu.js:256:31)
closeSubMenus @ blazorContextMenu.js:256

To Reproduce
Steps to reproduce the behavior:

  1. Click submenu item (which opens a window and closes the current context menu
  2. Error in the JS console.

Expected behavior
No error

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version 102.0.5005.62

Thank you for reporting this. I cannot reproduce it locally. Could you be so kind as to provide a project tha reproduces the bug ?

I've tried to reproduce the issue again, but somehow can't. Maybe the issue got fixed by the latest version or it was a cache issue. Anyway, closing this.

Not sure if it's best to comment here or open a new issue - but I think I have found the cause of this problem on line 280 of
BlazorContextMenu/BlazorContextMenu/wwwroot/blazorContextMenu.js:

            var closeSubMenus = function () {
                var childSubMenus = findAllChildsByClass(currentItemElement, "blazor-context-submenu");
                var i = childSubMenus.length;
                while (i--) {
                    var subMenu = childSubMenus[i];
                    blazorContextMenu.Hide(subMenu.id);
                }

                i = currentMenuList.childNodes.length;
                while (i--) {
                    var child = currentMenuList.children[i];  **// "childNodes" should be used here - not "children"** 
                    if (child == currentItemElement) continue;
                    child.removeEventListener("mouseover", closeSubMenus);
                }
            };