mwcraig / ipyevents

A custom widget for returning mouse and keyboard events to Python. Documentation:
https://ipyevents.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
112 stars 27 forks source link

prevent_default_action does not work if wheel event #75

Open deco-dev opened 1 year ago

deco-dev commented 1 year ago
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 commented 1 year ago

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 commented 1 year ago

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.