Skip to content

Commit fa8434b

Browse files
prutjemattlewis92
authored andcommitted
fix: round snap grids so dragging from each side is even
1 parent 2074c0a commit fa8434b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/draggable.directive.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
213213
map(moveData => {
214214
if (this.dragSnapGrid.x) {
215215
moveData.x =
216-
Math.floor(moveData.x / this.dragSnapGrid.x) *
216+
Math.round(moveData.x / this.dragSnapGrid.x) *
217217
this.dragSnapGrid.x;
218218
}
219219

220220
if (this.dragSnapGrid.y) {
221221
moveData.y =
222-
Math.floor(moveData.y / this.dragSnapGrid.y) *
222+
Math.round(moveData.y / this.dragSnapGrid.y) *
223223
this.dragSnapGrid.y;
224224
}
225225

test/draggable.directive.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('draggable directive', () => {
199199
clientY: 18
200200
});
201201
expect(fixture.componentInstance.dragging).to.have.been.calledWith({
202-
x: 0,
202+
x: 10,
203203
y: 8
204204
});
205205
triggerDomEvent('mousemove', draggableElement, {
@@ -243,7 +243,7 @@ describe('draggable directive', () => {
243243
});
244244
expect(fixture.componentInstance.dragging).to.have.been.calledWith({
245245
x: 8,
246-
y: 0
246+
y: 10
247247
});
248248
triggerDomEvent('mousemove', draggableElement, {
249249
clientX: 20,
@@ -361,7 +361,7 @@ describe('draggable directive', () => {
361361
y: 10
362362
});
363363
triggerDomEvent('mousemove', draggableElement, {
364-
clientX: 18,
364+
clientX: 14,
365365
clientY: 18
366366
});
367367
expect(fixture.componentInstance.dragging).to.have.been.calledOnce;

0 commit comments

Comments
 (0)