Skip to content

Commit 0f6b18d

Browse files
AntSan813Antonio Santos
andauthored
Fix position logic when item is dragged in from the outside (react-grid-layout#1915)
* fix position logic when item is dragged in from the outside * remove unnecessary code * undo dist/ change --------- Co-authored-by: Antonio Santos <[email protected]>
1 parent 66c238f commit 0f6b18d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/ReactGridLayout.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
714714
const finalDroppingItem = { ...droppingItem, ...onDragOverResult };
715715

716716
const { layout } = this.state;
717-
// This is relative to the DOM element that this event fired for.
718-
const { layerX, layerY } = e.nativeEvent;
717+
718+
const gridRect = e.currentTarget.getBoundingClientRect() // The grid's position in the viewport
719+
720+
// Calculate the mouse position relative to the grid
721+
const layerX = e.clientX - gridRect.left
722+
const layerY = e.clientY - gridRect.top
719723
const droppingPosition = {
720724
left: layerX / transformScale,
721725
top: layerY / transformScale,

0 commit comments

Comments
 (0)