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

Make menu appear next to cursor #36

Closed
madprops opened this issue Mar 4, 2022 · 1 comment
Closed

Make menu appear next to cursor #36

madprops opened this issue Mar 4, 2022 · 1 comment

Comments

@madprops
Copy link

madprops commented Mar 4, 2022

Sometimes the trigger button that is clicked to show the context menu is very long, in my case.

So if I click near the middle of it, the menu still appears on the top.

Wondering if there's a way to make the context menu appear near the location of the trigger click?

@nkappler
Copy link
Owner

nkappler commented Mar 4, 2022

Passing an event instead of an element to the show function should do the trick.
You can observe the difference on the demo page (https://nkappler.de/ctxmenu/)
The Button "Click this Button" passes an event and the menu sticks to the cursor, the 'button' below (which is a span element passes an element instead and the menu is attached to the elements coordinates.
Also see:
https://github.com/nkappler/ctxmenu#ctxmenushow

Code example

<!-- Use This:                                     v  -->
<button onclick="e => ctxmenu.show([ /* menu */ ], e)">Click this Button!</button>
<!-- Not This:                                       vvvvvv  -->
<button onclick="e => ctxmenu.show([ /* menu */ ], e.target)">Click this Button!</button>

3F48B084-21B9-4C00-9ECD-91816394AAC4

@nkappler nkappler closed this as completed Mar 4, 2022
@nkappler nkappler pinned this issue Apr 5, 2022
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

2 participants