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

prevent_default_action does not work if wheel event #75

Open
deco-dev opened this issue Nov 16, 2022 · 2 comments
Open

prevent_default_action does not work if wheel event #75

deco-dev opened this issue Nov 16, 2022 · 2 comments

Comments

@deco-dev
Copy link

deco-dev commented Nov 16, 2022

import ipywidgets as widgets
from ipywidgets import Label, HTML, HBox, Image, VBox, Box, HBox, Textarea, Layout
from ipyevents import Event 
from IPython.display import display

c = ""
for i in range(100):
   c += "%daaaaaaaaaaaaaaaaaaaaa\n" % i
   
text =Textarea(c, layout=Layout(height='200px', width='200px'))
h = HTML('Event info')
d = Event(source=text, watched_events=['wheel'], prevent_default_action=False)

def handle_event_default_demo(event):
   lines = ['{}: {}'.format(k, v) for k, v in event.items()]
   content = ' '.join(lines)
   h.value = content
d.on_dom_event(handle_event_default_demo)
display(text, h)

I tested above code, the default wheel action does not work. The textarea scroll does not move.
I want to know scroll movement of textarea.

@deco-dev
Copy link
Author

deco-dev commented Nov 16, 2022

I found the code.

        if ((event.type == 'wheel') || this.get('prevent_default_action')) {
            // Really want both of these, one to stop any default action
            // and the other to ensure no other listeners pick it up.
            event.preventDefault()
            event.stopPropagation()
        }

why does default action prevent if wheel?

@mwcraig
Copy link
Owner

mwcraig commented Nov 29, 2022

Sorry for the long delay -- if I remember right, the wheel event is not propagated to make sure that the notebook itself does not scroll. In this specific case -- a scrollable TextArea in a notebook -- I think allowing propagation would be fine because I suspect that the TextArea itself stops further propagation.

Is there another event you could monitor besides wheel, or make observe for a change in value of the TextArea? I can take a look next week at which widgets are themselves scrollable to try to avoid this issue for those widgets.

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