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

Preventing context menu in jupyter-widget output #3521

Closed
vidartf opened this issue Jan 3, 2018 · 11 comments · Fixed by #3527
Closed

Preventing context menu in jupyter-widget output #3521

vidartf opened this issue Jan 3, 2018 · 11 comments · Fixed by #3527
Assignees
Labels
bug pkg:notebook status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@vidartf
Copy link
Member

vidartf commented Jan 3, 2018

I was playing around with pythreejs today in jupyterlab (it creates a WebGL context as its widget view), and I noticed that when I pan the scene by dragging with the right-click mouse button, I always get the context menu when I release the button.

The drag handler in question registers for several events, among others doing this:

element.addEventListener( 'contextmenu', onContextMenu, false );
element.addEventListener( 'mousedown', onMouseDown, false );

function onContextMenu( event ) {
  event.preventDefault();
}
function onMouseDown( event ) {
  event.preventDefault();
  document.addEventListener( 'mouseup', onMouseUp, false );
}

function onMouseUp( event ) {
  // preventDefault and/or stopPropagation seems to have no effect here
  document.removeEventListener( 'mouseup', onMouseUp, false );
}

What is the right way to prevent the context menu from showing in this case? I'd prefer it to show up for other cases (e.g. when these controls are not enabled).

@vidartf
Copy link
Member Author

vidartf commented Jan 3, 2018

(note, in the example code element is the HTMLCanvas element of the WebGL context)

@blink1073
Copy link
Member

I think these selectors need to be scoped to :focus as we do in the shortcuts.

@OKaluza
Copy link

OKaluza commented May 27, 2019

This is not fixed, or the fix has been regressed, using Version 0.35.4

@zerline
Copy link
Contributor

zerline commented May 28, 2019

I have the same problem on my jupyterlab 0.35.6

@vidartf
Copy link
Member Author

vidartf commented May 30, 2019

@OKaluza / @zerline Would you mind sharing steps to reproduce your issue? Are you using pythreejs, or something else? Which events are you listening to / preventing?

@OKaluza
Copy link

OKaluza commented May 30, 2019

@vidartf I'm using my own html and WebGL components, but in general anywhere I click in the output cell has the jupyterlab context menu, even controls that have focus.
You can test with the example provided in the fix: #3527

input("""foo
bar""")

Execute above and try right clicking on the produced input field, it should show the default browser context menu. I can put together an example using a WebGL component if that helps.

I would say there's a lot to be said for not having the custom context menu appear for output cells at all. For example: if an image is produced you can't use the browser features for saving or copying the image (well you can still get it with shift, but not everyone will be aware of that).

I have since worked around it where it matters in my code by calling stopPropogation() in the contextmenu event for my components.

@jasongrout
Copy link
Contributor

well you can still get it with shift, but not everyone will be aware of that

We've added an item to the context menu telling people about the shift-click to get to the native menu.

@zerline
Copy link
Contributor

zerline commented May 30, 2019

@jasongrout @vidartf thank you for your help. I probably should check even more, but until now, I still can't see my right-click menus (from francy-widget) on jupyterlab -- although I see them very well on the notebook.

  1. with a right-click, I see the jupyterlab context menu everywhere on the windows ; even on an element which has focus and specialized cursor

  2. with a shift-right-click, I see the underlying browser context menu instead of the jupyterlab context menu ; but never can I see the francy modal menu

@vidartf
Copy link
Member Author

vidartf commented May 31, 2019

The last PR I can find that touched that code is #3554. @blink1073 / @ellisonbg / @jasongrout you were the most involved in that PR, and I'm struggling to follow the rather long discussions and big code changes. Was this an intended reversion, or a regression?

@blink1073
Copy link
Member

Yes, that PR switches us to using the capture phase for the context menu, which simplified our selector logic across the board. We added instructions for extension authors here. Current docs link: https://github.com/jupyterlab/jupyterlab/blob/master/docs/source/developer/extension_dev.rst#context-menus

@lock
Copy link

lock bot commented Aug 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related discussion.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 6, 2019
@jasongrout jasongrout added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug pkg:notebook status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants