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

How do I prevent scrolling? #1229

Closed
taylorgoolsby opened this issue Dec 9, 2018 · 3 comments
Closed

How do I prevent scrolling? #1229

taylorgoolsby opened this issue Dec 9, 2018 · 3 comments
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@taylorgoolsby
Copy link

taylorgoolsby commented Dec 9, 2018

"monaco-editor": "^0.15.1", via the react-monaco-editor package.
**Browser: Version 71.0.3578.80 (Official Build) (64-bit)
**OS: macOS 10.14.1 (18B75)

It appears that there is no way to prevent scrolling. For regular HTML elements, I can prevent scrolling by calling e.preventDefault() anywhere. I'm guessing scrolling is handled by the browser if the top-level document or window receives a wheel event which is not defaultPrevented.

I am building a UI where ctrl + wheel is interpreted as a zoom and it is used to scale the entire application.

The problem is when my mouse is over the monaco editor, and I do ctrl + wheel, I want to use e.preventDefault() to prevent the editor from scrolling just how it would prevent scroll if it was a regular HTML element.

Is there anyway I can prevent scrolling? Is this intended or is it a bug that e.preventDefault() doesn't prevent scrolling like it does with HTML elements?

Here is a code example

I expect scrolling to to be prevented with this code:

<div
  onWheel={(e) => {
    e.preventDefault()
  }}
>
  <MonacoEditor
    width={300}
    height={300}
    language="markdown"
  />
</div>
@alexdima
Copy link
Member

alexdima commented Jan 9, 2019

@taylorgoolsby Perhaps you can capture the event before the bubbling phase and stop propagation? (e.stopPropagation()) In simple DOM API that would be the third argument, true: domNode.addEventListener('wheel', () => {...}, true). That would make it that you get the event before it is sent to its target.

@taylorgoolsby
Copy link
Author

@alexandrudima It's been a while since I've posted, and since then I switched to different IDE besides monaco. I remember trying out stopping on the capture phase, but it didn't work. When I get the time, I'll checkout the old commits and try it again.

@geyang
Copy link

geyang commented Jun 16, 2019

@taylorgoolsby it is not an IDE, it is an editor :)

@alexdima alexdima added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Dec 13, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants