Skip to content

Commit

Permalink
Fix size issues when not using border-box
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Jun 21, 2018
1 parent 05df994 commit 0bdfc3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 19 additions & 5 deletions src/eventHandlers/mousedown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,37 @@ function createGhost(
node: VNode
): VNode {
const rect = item.getBoundingClientRect();
const style = getComputedStyle(item);
const padding = {
top: parseFloat(style.paddingTop) + parseFloat(style.borderTop),
left: parseFloat(style.paddingLeft) + parseFloat(style.borderLeft),
bottom:
parseFloat(style.paddingBottom) + parseFloat(style.borderBottom),
right: parseFloat(style.paddingRight) + parseFloat(style.borderRight)
};
const parentRect = item.parentElement.getBoundingClientRect();
const offsetX = ev.clientX - rect.left + parentRect.left;
const offsetY = ev.clientY - rect.top + parentRect.top;
const offsetX =
ev.clientX - rect.left + parentRect.left + parseFloat(style.marginLeft);
const offsetY =
ev.clientY - rect.top + parentRect.top + parseFloat(style.marginTop);

const sub = style.boxSizing !== 'border-box';

return addDataEntry(
addDataEntry(node, 'dataset', {
offsetX,
offsetY,
item
item,
ghost: true
}),
'style',
{
position: 'absolute',
left: ev.clientX - offsetX + 'px',
top: ev.clientY - offsetY + 'px',
width: rect.width + 'px',
height: rect.height + 'px',
width: rect.width - (sub ? padding.left - padding.right : 0) + 'px',
height:
rect.height - (sub ? padding.top - padding.bottom : 0) + 'px',
'pointer-events': 'none'
}
);
Expand Down
6 changes: 4 additions & 2 deletions src/eventHandlers/mousemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export function mousemoveHandler(
.map(n => n.data.dataset.item)
.filter(n => !!n)[0];

const siblings = Array.prototype.slice.call(item.parentElement.children);
const siblings: Element[] = Array.prototype.slice.call(
item.parentElement.children
);
const index = siblings.indexOf(item);
const ghost = siblings[siblings.length - 1];
const ghost = siblings.filter(el => (el as any).dataset.ghost)[0];
const itemArea = getArea(ghost);
let swapIndex = index;

Expand Down

0 comments on commit 0bdfc3c

Please sign in to comment.