Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closeMenu method documentation #22

Closed
smalos opened this issue Aug 11, 2021 · 6 comments
Closed

closeMenu method documentation #22

smalos opened this issue Aug 11, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@smalos
Copy link

smalos commented Aug 11, 2021

Add documentation for the closeMenu method:

E.g. The closeMenu method is used to close an open context menu.

@nkappler
Copy link
Owner

The closeMenu method is not intended to be part of the public API, it is an internal method right now.
Do you have a specific need for it and can describe the use case in more detail?

Thank you

@smalos
Copy link
Author

smalos commented Aug 11, 2021

The menu doesn't close when the parent element (e.g. document body) is clicked.
Since ev.target.parentElement is null, closeMenu() is not called.
My workaround is to use another, already existing listener that calls closeMenu().

    window.addEventListener("click", function (ev) {
      var item = ev.target && ev.target.parentElement;

      if (item && item.className !== "interactive") {
        _this.closeMenu();
      }
    });

@nkappler
Copy link
Owner

This sounds like a bug.
Do you have an example (webiste or codesandbox) for this?

@nkappler
Copy link
Owner

in which browser did you observe this?
parentElement of document body should be html and not null

image

@nkappler nkappler added the bug Something isn't working label Aug 17, 2021
@smalos
Copy link
Author

smalos commented Aug 17, 2021

When I run this JS in the developer console while the menu is open,
document.getElementsByClassName("ctxmenu")[0].parentNode
or jQuery notation $('.ctxmenu').parent()

I get this back:
<body id=​"nubody" onload=​"nuLoad()​" onresize=​"nuResize()​" class=​"nuEditBody" title=​"ID:​ nubody" style=​"transform:​ scale(1)​;​ width:​ 100%;​ height:​ 185px;​">​…​</body>​

Only the parent of the parent will be html

$('.ctxmenu').parent().parent()

You can check out demo.nubuilder.com and right-click any button.

@nkappler
Copy link
Owner

nkappler commented Aug 19, 2021

I think I know whats going on:
Your body element doesn't cover the whole viewport:
grafik

This is probably why the event's target is html when it usually is body.
And the parent of html is obviously null...
I'll add a check if the target is html as well.

Thanks for reporting this 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants