Skip to content

Commit 185e804

Browse files
feat(ui): Add pointer coordinates and drop zone rect to ct-drop event (commontoolsinc#2223)
The ct-drop-zone component now emits additional data in the ct-drop event: - pointerX/pointerY: The cursor coordinates at drop time - dropZoneRect: The bounding rect of the drop zone (left, top, width, height) This enables patterns to calculate precise drop positions within the zone, which is necessary for implementing drag-and-drop features like placing tiles on a game board where shadow DOM isolation prevents DOM queries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: tonyespinoza1 <tonyespinoza1@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e292a9c commit 185e804

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/ui/src/v2/components/ct-drop-zone/ct-drop-zone.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,21 @@ export class CTDropZone extends BaseElement {
164164
// Emit leave event before drop (dropping is a form of leaving)
165165
this.emit("ct-drag-leave", {});
166166

167-
// Emit drop event
167+
// Get drop zone bounding rect for position calculation in handler
168+
const dropZoneRect = this.getBoundingClientRect();
169+
170+
// Emit drop event with pointer coordinates and drop zone rect
168171
this.emit("ct-drop", {
169172
sourceCell: dragState.cell,
170173
type: dragState.type,
174+
pointerX: dragState.pointerX,
175+
pointerY: dragState.pointerY,
176+
dropZoneRect: {
177+
left: dropZoneRect.left,
178+
top: dropZoneRect.top,
179+
width: dropZoneRect.width,
180+
height: dropZoneRect.height,
181+
},
171182
});
172183
}
173184
}

0 commit comments

Comments
 (0)