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

auto close context menu when clicking on another selector #48

Closed
cantonic opened this issue May 23, 2012 · 4 comments
Closed

auto close context menu when clicking on another selector #48

cantonic opened this issue May 23, 2012 · 4 comments

Comments

@cantonic
Copy link

First let me thank you for that great plugin! I have implemented that in an application of mine where i have a table with multiple rows. each row is right-clickable and opens the context menu, but when I right-click on row no.1 for example and then right-click on row 2 it just closes the first opened context menu from row 1. then i have to do a second right-click on row 2 in order to open the context menu. It would be a much better user experience if a click on row 2 would automatically close the first context menu and open the second one.

@rodneyrehm
Copy link
Contributor

While I agree with your assessment, I (currently) don't see any reliable way to implement it.

Whenever a menu is shown, a transparent layer is put behind it. This layer is supposed to guarantee that a click anywhere outside of the menu would either close or reposition the menu. I would've preferred to bind an event to document and act from there. While that approach worked fine for me, other people had quite the difficulties with other widgets on their site (namely if the widgets stopPropagation() of certain events). This layer is the reason why your second table row never receives the click.

We could introduce an option that lets you enable/disable the layer thing. So the safe option would be to use the layer and not care about what other widgets on the page do. Disabling the layer would lead to binding a mousedown event to document to hide the menu when necessary. Should a menu be open and one clicked on another widget, this event handler might never be executed. It would be the responsibility of the implementor to make sure menus close when they need to.

If this solution is something you can work with, I would look into it "soon".

@cantonic
Copy link
Author

Yeah, i think there is no other way of implementing this than introducing an option to enable/disable the layer stuff. It would be great if you could implement that ;)

@rodneyrehm
Copy link
Contributor

I looked into this more closely. Apparently I will not be able to get rid of the backdrop-layer that easily.
Instead I would try to use document.elementFromPoint (spec) to find out if you clicked on another triggering element. This will not work in older browsers - but it won't break them either.

@rodneyrehm
Copy link
Contributor

Implemented and released in version 1.5.15. You only have to update the source, no furthor action required :)

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