How do I get the coordinates of my dropped item relative to the drop target container?
See original GitHub issueI am working with 1.0.0-rc.
In drag-around-naive
:
const boxTarget = {
drop(props, monitor, component) {
const item = monitor.getItem();
const delta = monitor.getDifferenceFromInitialOffset();
const left = Math.round(item.left + delta.x);
const top = Math.round(item.top + delta.y);
component.moveBox(item.id, left, top);
}
};
At present it looks like I need to get the offset from the page of the original item, then I can find the offset from the page of where I dropped, then I need to find the offset of the drop container from the page, then do that calculation and I have the relative position in my drop target container.
This seems like a lot of work for something pretty common…
Issue Analytics
- State:
- Created 8 years ago
- Reactions:15
- Comments:22 (2 by maintainers)
Top Results From Across the Web
Get co-ordinates in relation to drop target with Draggable
After an item has been successfully dropped I need to get the X and Y co-ordinates of the dropped item in relation to...
Read more >Get element position in the DOM on React DnD drop?
Workbench: const boxTarget = { drop(props, monitor, component) { const item = monitor. getItem() console. log(component, item.
Read more >Drag and Drop | Ext JS 6.2.0
A drag operation, essentially, is a click gesture on some UI element while ... We'll need to make the rented, repair and vehicle...
Read more >ondrop Event
The ondrop event occurs when a draggable element or text selection is dropped on a valid drop target. Drag and drop is a...
Read more >Introduction to JavaScript Drag and Drop API
The dragenter event fires as soon as you drag the element over a drop target. After the dragenter event fires, the dragover event...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I guess we could have this for symmetry. For now, you can just use
findDOMNode(component).getBoundingClientRect()
, but I wouldn’t mind adding this if more people voice support. Let’s keep this open and see what others say.@gaearon I’m interested in generalized solution. How can we use
react-dnd-html5-backend
instead ofgetBoundingClientRect
directly?