Skip to content

Commit 26cfa7e

Browse files
author
Matt Lewis
committed
fix(draggable): make the dragEnd output respect the validateDrag input
1 parent 13d60e5 commit 26cfa7e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/draggable.directive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class Draggable implements OnInit, OnDestroy {
135135
return isInside(this.dragContainer.getBoundingClientRect(), newRect);
136136

137137
})
138+
.filter(({x, y}) => !this.validateDrag || this.validateDrag({x, y}))
138139
.takeUntil(Observable.merge(this.mouseUp, this.mouseDown));
139140

140141
mouseMove.takeLast(1).subscribe(({x, y}) => {
@@ -149,7 +150,6 @@ export class Draggable implements OnInit, OnDestroy {
149150
return mouseMove;
150151

151152
})
152-
.filter(({x, y}) => !this.validateDrag || this.validateDrag({x, y}))
153153
.share();
154154

155155
Observable

test/draggable.directive.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ describe('draggable directive', () => {
249249
expect(fixture.componentInstance.dragging).not.to.have.been.calledWith({x: 2, y: -2});
250250
triggerDomEvent('mousemove', draggableElement, {clientX: 7, clientY: 12});
251251
expect(fixture.componentInstance.dragging).to.have.been.calledWith({x: 2, y: 2});
252+
triggerDomEvent('mousemove', draggableElement, {clientX: 3, clientY: 10});
253+
expect(fixture.componentInstance.dragging).not.to.have.been.calledWith({x: -2, y: 0});
254+
triggerDomEvent('mouseup', draggableElement, {clientX: 3, clientY: 10});
255+
expect(fixture.componentInstance.dragEnd).to.have.been.calledWith({x: 2, y: 2});
252256
});
253257

254258
it('should only call the dragEnd event once', () => {

0 commit comments

Comments
 (0)