-
Notifications
You must be signed in to change notification settings - Fork 6
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
Access parent menu selected target #44
Comments
Hi Max, every submenu is a direct ChildElement of the parent list item that it belongs to. <ul class="ctxmenu" style="position: fixed; left: 646px; top: 493px;">
<li title="" class="interactive"><span>Add marker</span></li>
<li title="" class="interactive"><span>Delete all markers</span></li>
<li title="" class="interactive submenu">
<span>Go to marker</span>
<ul class="ctxmenu" style="position: fixed; left: 501.406px; top: 539px;">
<li title="" class="interactive"><span>"New Marker"</span></li>
</ul>
</li>
</ul> This means that while there is no dedicated API for this, you can achieve this via the DOM: <body id="body" style="width: 100vw; height: 100vh;">
<script>
ctxmenu.attach("#body", [
{
text: "Parent",
subMenu: [
{
text: "child",
action: (event) => {
const childListItem = event.target.parentElement;
const submenu = childListItem .parentElement;
const parentListItem = submenu.parentElement;
console.log(parentListItem );
}
}
]
}
])
</script>
</body> Note that a default menu item has an extra span to wrap the text, hence the extra You might need to modify this example a bit, depending on which type of item you are trying to achieve this, but it is totally doable 😊 Happy Coding |
@nkappler Thanks for the fast response, you rock ! so I am trying to access the text of the parent item, now in your example would appreciate your advice if there is more suitable way to access the parent menu selected item text Thanks.
|
Hi Max,
parentListItem.querySelector("span").innerText |
Thanks @nkappler , this works perfectly. While on the subject of parent menus, is there a way to get a callback function not on "select" but on "hover" or "mouseenter" event; i mean obviously the mouseenter event opens the sub-menu, but could I pass extra functionality besides this. I am closing this issue since its solved, thanks alot. lemme know if its ok to open another one for the mouseenter event if its doable :) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I've created another Issue to track this feature request and keep this issue clean, since I've pinned it. |
Hi there,
Thanks for the great context menu library, finally a flexible library.
I have one request, is there a way to access the parent menu selected Item ?
I have a scenario where i have multiple sub-menues but once the item in the last sub-menu is selected i need the callback function in it to access the targets from the parent menus that caused the sub-menues to open.
is there a way to achieve that ? cause i noticed that the target object right now doesn't include information about the parent menu item that opened this submenu
The text was updated successfully, but these errors were encountered: