Skip to content

Commit a77d07a

Browse files
author
Matt Lewis
committed
feat(snapGrid): rename to dragSnapGrid
BREAKING CHANGE: The snapGrid input has been renamed to dragSnapGrid Closes #7
1 parent d03a944 commit a77d07a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

demo/demo.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Component} from '@angular/core';
66
<div mwlDraggable dropData="foo">
77
Drag me!
88
</div>
9-
<div mwlDraggable dropData="bar" [snapGrid]="{x: 100, y: 100}">
9+
<div mwlDraggable dropData="bar" [dragSnapGrid]="{x: 100, y: 100}">
1010
I snap to a 100x100 grid
1111
</div>
1212
<div

src/draggable.directive.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Draggable implements OnInit, OnDestroy {
2323

2424
@Input() dragAxis: DragAxis = {x: true, y: true};
2525

26-
@Input() snapGrid: SnapGrid = {};
26+
@Input() dragSnapGrid: SnapGrid = {};
2727

2828
@Input() ghostDragEnabled: boolean = true;
2929

@@ -69,12 +69,12 @@ export class Draggable implements OnInit, OnDestroy {
6969
})
7070
.map((moveData: Coordinates) => {
7171

72-
if (this.snapGrid.x) {
73-
moveData.x = Math.floor(moveData.x / this.snapGrid.x) * this.snapGrid.x;
72+
if (this.dragSnapGrid.x) {
73+
moveData.x = Math.floor(moveData.x / this.dragSnapGrid.x) * this.dragSnapGrid.x;
7474
}
7575

76-
if (this.snapGrid.y) {
77-
moveData.y = Math.floor(moveData.y / this.snapGrid.y) * this.snapGrid.y;
76+
if (this.dragSnapGrid.y) {
77+
moveData.y = Math.floor(moveData.y / this.dragSnapGrid.y) * this.dragSnapGrid.y;
7878
}
7979

8080
return moveData;

test/draggable.directive.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('draggable directive', () => {
1313
<div
1414
mwlDraggable
1515
[dragAxis]="dragAxis"
16-
[snapGrid]="snapGrid"
16+
[dragSnapGrid]="dragSnapGrid"
1717
[ghostDragEnabled]="ghostDragEnabled"
1818
(dragStart)="dragStart($event)"
1919
(dragging)="dragging($event)"
@@ -28,7 +28,7 @@ describe('draggable directive', () => {
2828
public dragging: sinon.SinonSpy = sinon.spy();
2929
public dragEnd: sinon.SinonSpy = sinon.spy();
3030
public dragAxis: any = {x: true, y: true};
31-
public snapGrid: any = {};
31+
public dragSnapGrid: any = {};
3232
public ghostDragEnabled: boolean = true;
3333

3434
}
@@ -123,7 +123,7 @@ describe('draggable directive', () => {
123123
});
124124

125125
it('should snap all horizontal drags to a grid', () => {
126-
fixture.componentInstance.snapGrid = {x: 10};
126+
fixture.componentInstance.dragSnapGrid = {x: 10};
127127
fixture.detectChanges();
128128
const draggableElement: HTMLElement = fixture.componentInstance.draggable.element.nativeElement;
129129
triggerDomEvent('mousedown', draggableElement, {clientX: 5, clientY: 10});
@@ -140,7 +140,7 @@ describe('draggable directive', () => {
140140
});
141141

142142
it('should snap all vertical drags to a grid', () => {
143-
fixture.componentInstance.snapGrid = {y: 10};
143+
fixture.componentInstance.dragSnapGrid = {y: 10};
144144
fixture.detectChanges();
145145
const draggableElement: HTMLElement = fixture.componentInstance.draggable.element.nativeElement;
146146
triggerDomEvent('mousedown', draggableElement, {clientX: 10, clientY: 5});
@@ -157,7 +157,7 @@ describe('draggable directive', () => {
157157
});
158158

159159
it('should snap all vertical and horizontal drags to a grid', () => {
160-
fixture.componentInstance.snapGrid = {y: 10, x: 10};
160+
fixture.componentInstance.dragSnapGrid = {y: 10, x: 10};
161161
fixture.detectChanges();
162162
const draggableElement: HTMLElement = fixture.componentInstance.draggable.element.nativeElement;
163163
triggerDomEvent('mousedown', draggableElement, {clientX: 10, clientY: 5});

0 commit comments

Comments
 (0)