Droppable

pz.droppable(content, id) makes content a place where dragged items can be dropped:
a trash can, a folder, an upload area, a canvas, an input port.
pz.droppable( ui.card(pz.row([pz.icon("trash-2"), ui.label("Drop to delete")])), "trash", accepts="file", # only draggables of this type on_drop=lambda e: self.delete(e.data),)Who it takes
Section titled “Who it takes”acceptslists thetypes (or sortablegroups) it takes.None(the default) or"*"takes everything.can_drop(event)adds any rule of yours. It is asked once per drag, the first time the drag reaches the target, withevent.datathe dragged item, and returnsTrueorFalse.disabled=Truerefuses everything.
A refused drag shows a “not allowed” cursor while it is over the target. More in conditions.
How it looks
Section titled “How it looks”| Option | Default | Effect |
|---|---|---|
over_style |
the theme’s | While a drag it takes is over it. |
active_style |
False |
While a drag it takes is in progress anywhere: show the user where they can drop. |
placeholder |
"none" |
"shadow" (a box where the item will land) or "ghost" (a translucent copy). |
placeholder_style |
the theme’s | The look of the shadow. |
ghost_opacity |
0.4 |
The opacity of the ghost. |
Styles are True (the theme’s accent look), a color, a dict with background,
border_color, border_width and radius, or False:
pz.droppable(area, "upload", over_style={"background": "#5c78e220", "border_color": "#5c78e2", "border_width": 2, "radius": 12})Where it lands
Section titled “Where it lands”The drop event says where the item lands inside the target: event.x, event.y (the pointer)
and event.item_x, event.item_y (the item’s top-left corner). That is all a free canvas
needs:
def drop(self, e): self.shapes[e.source].update(x=e.item_x, y=e.item_y)snap=10 rounds that place to a grid and guides=True aligns it with the other items, with
pink guides like Figma’s. See free canvas.
Events
Section titled “Events”| Event | When |
|---|---|
on_drop(event) |
An item was dropped on it. |
on_enter(event) |
A drag it takes came over it. |
on_over(event) |
The landing place changed (event.item_x, event.x…). |
on_leave(event) |
The drag left it, or was cancelled. |
Targets can be nested: the deepest one under the pointer that takes the drag wins (a column inside a page inside a canvas).