Clipboard
New in 0.5.6
The Clipboard component can be used to respond to paste events with complex data.
If the Clipboard component is included in a page without children,
rx.clipboard()
, then it will attach to the document's paste
event handler
and will be triggered when data is pasted anywhere into the page.
The data
argument passed to the on_paste
method is a list of tuples, where
each tuple contains the MIME type of the pasted data and the data itself. Binary
data will be base64 encoded as a data URI, and can be decoded using python's
urlopen
or used directly as the src
prop of an image.
Scoped Paste Events
If you want to limit the scope of the paste event to a specific element, wrap
the rx.clipboard
component around the elements that should trigger the paste
event.
To avoid having outer paste handlers also trigger the event, you can use the
event action .stop_propagation
to prevent the paste from bubbling up through
the DOM.
If you need to also prevent the default action of pasting the data into a text
box, you can also attach the .prevent_default
action.