angular2-draggable
angular2-draggable copied to clipboard
Is it possible to drag a FAB without activating its click event?
<div class="fab-add" ngDraggable>
<button mat-mini-fab color="primary" (click)="runStuff()" >
<mat-icon>add</mat-icon>
</button>
</div>
Just some parting thoughts, but haven't tried any of this code out myself.
- Could you get away with something like an
$event.stopPropogation()
in the containing div - Have you tried adding ngDraggable to the button directly? Will that work for you?
- Can you use different events than click, such as mouseup? https://stackoverflow.com/questions/6042202/how-to-distinguish-mouse-click-and-drag
You can check if the FAB moved or it was only clicked.
<div ngDraggable (endOffset)="onMoveEnd($event)">
<button (click)="runStuff()">Add</button>
</div>
lastPos = { x: 0, y: 0 };
offset = { x: 0, y: 0 }
runStuff() {
if (this.offset.x === 0 && this.offset.x === 0) {
console.log('clicked')
}
}
onMoveEnd(event) {
this.offset = { x: event.x - this.lastPos.x, y: event.y - this.lastPos.y };
this.lastPos = event;
}