Skip to content

Commit

Permalink
fix:Fix sortableContainer distance inaccurate
Browse files Browse the repository at this point in the history
  • Loading branch information
李名顺 committed Jul 31, 2022
1 parent caf3c4f commit be1ed3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SortableContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getElementMargin,
getLockPixelOffsets,
getPosition,
getLinearDistance,
isTouchEvent,
limit,
NodeType,
Expand Down Expand Up @@ -191,7 +192,7 @@ export default function sortableContainer(
x: this.position.x - position.x,
y: this.position.y - position.y,
};
const combinedDelta = Math.abs(delta.x) + Math.abs(delta.y);
const combinedDelta = getLinearDistance(Math.abs(delta.x), Math.abs(delta.y));

this.delta = delta;

Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ export function getContainerGridGap(element) {
return {x: 0, y: 0};
}

export function getLinearDistance(deltaX, deltaY) {
return Math.sqrt(deltaX ** 2, deltaY ** 2);
}

export const KEYCODE = {
TAB: 9,
ESC: 27,
Expand Down

0 comments on commit be1ed3b

Please sign in to comment.