support event delegation #4611
Replies: 3 comments 2 replies
-
related: #4606 It'll make it easier to customize(hacking) a complex component like the markdown, we can inject html snippets into the component, but handle the events on the component itself, it'll distinguish different children by some data attributes. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion, @yihuang! To clarify: ui.button('A').on_click(lambda e: print(e.sender))
ui.button('B').on_click(lambda e: print(e.sender))
with ui.card().on('click', lambda e: print(e.sender)):
ui.button('C')
ui.button('D') Clicking A or B yields information about which button was clicked. But clicking C or D only informs us that the card was clicked. I'm not sure about the Maybe I'm confusing two things:
Point 1 will work for any HTML elements, even nested ones inside |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Event delegation is to register a common event handler on a parent element to handle events for multiple child elements, because the event bubbles up, in javascript one can tell which child triggers the event from the
event.target
field.Currently the
event.target
is not sent back to server side because it's a dom node, but we can try to sent back some information, like the component idc***
to server side where it can be mapped to a component.Propose
{ cid: "c***", tag: "", data: { ... } }
,cid
is the id of enclosing component,tag
anddata
is information of the exact dom node, data is object of the data attributes on the dom node.Beta Was this translation helpful? Give feedback.
All reactions