From 0c571bbce89e559c956b8809e41bd99aa22a251e Mon Sep 17 00:00:00 2001 From: A Jordan Simonds Date: Mon, 15 Feb 2021 21:05:57 -0500 Subject: [PATCH] fix: Account for margin in drag and drop --- src/ContainerMixin.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ContainerMixin.js b/src/ContainerMixin.js index 6558ce2a..1c4f37e6 100644 --- a/src/ContainerMixin.js +++ b/src/ContainerMixin.js @@ -329,6 +329,11 @@ export const ContainerMixin = { intializeOffsets(e, clientRect) { const { useWindowAsScrollContainer, containerBoundingRect, _window } = this; + this.marginOffset = { + x: this.margin.left + this.margin.right, + y: Math.max(this.margin.top, this.margin.bottom), + }; + this._axis = { x: this.axis.indexOf('x') >= 0, y: this.axis.indexOf('y') >= 0, @@ -389,10 +394,10 @@ export const ContainerMixin = { this.container.appendChild(this.sortableGhost); const ghostRect = this.sortableGhost.getBoundingClientRect(); this.boundingClientRect = ghostRect; + this.margin = getElementMargin(this.sortableGhost); this.width = ghostRect.width; this.height = ghostRect.height; - this.marginOffset = { x: 0, y: 0 }; this.intializeOffsets(e, helperBoundingRect); this.offsetEdge = { top: helperBoundingRect.top + this.initialScroll.top + this.initialWindowScroll.top,