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

Support Callback Functions for Submenus #45

Closed
nkappler opened this issue Sep 4, 2023 · 0 comments
Closed

Support Callback Functions for Submenus #45

nkappler opened this issue Sep 4, 2023 · 0 comments

Comments

@nkappler
Copy link
Owner

nkappler commented Sep 4, 2023

I was expecting this modified example to do what you want:

ctxmenu.attach("#body", [
            {
                text: "Parent",
                subMenu: function beforeOpenSubMenu() {
                    alert("beforeOpenSubmenu");

                    return [
                        {
                            text: "child",
                            action: (event) => {
                                const childListElement = event.target.parentElement;
                                const submenu = childListElement.parentElement;
                                const parentListElement = submenu.parentElement;
                                console.log(parentListElement.querySelector("span").innerText);
                            }
                        }
                    ];
                }
            }
        ], function beforeOpen(menu) {
            alert("BeforeOpen")

            return menu;
        });

You can pass a function as a third parameter to the attach method, which will be called before the root menu opens.
Note that the function receives the menu definition as a parameter and also has to return it.
You can modify it as you please, but this function needs to return a valid menu definition.

As per my own documentation, you should also be able to pass a function to generate the submenu (beforeOpenSubMenu), however the Parent list item ends up being disabled.
It's been a while that I wrote this code and honestly the test coverage is at best mediocre, since it depends on manual testing,
but I am pretty sure that this is a bug.

The beforeOpenSubMenu should be called just before the submenu is being opened, but currently it is never called.
I've created a new bug #45 to track this.

Originally posted by @nkappler in #44 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant