Skip to content

Commit 897b3fe

Browse files
author
Matt Lewis
committed
feat(draggable): allow the draggable cursor to be customised
1 parent c79ce75 commit 897b3fe

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/draggable.directive.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
6262

6363
@Input() validateDrag: ValidateDrag;
6464

65+
@Input() dragCursor = MOVE_CURSOR;
66+
6567
@Output()
6668
dragStart: EventEmitter<Coordinates> = new EventEmitter<Coordinates>();
6769

@@ -120,7 +122,7 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
120122
this.dragStart.next({ x: 0, y: 0 });
121123
});
122124

123-
this.setCursor(MOVE_CURSOR);
125+
this.setCursor(this.dragCursor);
124126

125127
const currentDrag: Subject<any> = new Subject();
126128

@@ -369,7 +371,7 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
369371
}
370372

371373
private onMouseEnter(): void {
372-
this.setCursor(MOVE_CURSOR);
374+
this.setCursor(this.dragCursor);
373375
}
374376

375377
private onMouseLeave(): void {

test/draggable.directive.spec.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ describe('draggable directive', () => {
1515
[dragSnapGrid]="dragSnapGrid"
1616
[ghostDragEnabled]="ghostDragEnabled"
1717
[validateDrag]="validateDrag"
18+
[dragCursor]="dragCursor"
1819
(dragStart)="dragStart($event)"
1920
(dragging)="dragging($event)"
2021
(dragEnd)="dragEnd($event)">
2122
Drag me!
2223
</div>`
2324
})
2425
class TestComponent {
25-
@ViewChild(DraggableDirective) public draggable: DraggableDirective;
26-
public dragStart: sinon.SinonSpy = sinon.spy();
27-
public dragging: sinon.SinonSpy = sinon.spy();
28-
public dragEnd: sinon.SinonSpy = sinon.spy();
29-
public dragAxis: any = { x: true, y: true };
30-
public dragSnapGrid: any = {};
31-
public ghostDragEnabled: boolean = true;
32-
public validateDrag: ValidateDrag;
26+
@ViewChild(DraggableDirective) draggable: DraggableDirective;
27+
dragStart: sinon.SinonSpy = sinon.spy();
28+
dragging: sinon.SinonSpy = sinon.spy();
29+
dragEnd: sinon.SinonSpy = sinon.spy();
30+
dragAxis: any = { x: true, y: true };
31+
dragSnapGrid: any = {};
32+
ghostDragEnabled: boolean = true;
33+
validateDrag: ValidateDrag;
34+
dragCursor = 'move';
3335
}
3436

3537
beforeEach(() => {
@@ -533,4 +535,15 @@ describe('draggable directive', () => {
533535
});
534536
expect(draggableElement.style.transform).not.to.be.ok;
535537
});
538+
539+
it('should disable the mouse move cursor', () => {
540+
fixture.componentInstance.dragCursor = '';
541+
fixture.detectChanges();
542+
const draggableElement: HTMLElement =
543+
fixture.componentInstance.draggable.element.nativeElement;
544+
triggerDomEvent('mouseenter', draggableElement);
545+
expect(draggableElement.style.cursor).not.to.be.ok;
546+
triggerDomEvent('mouseleave', draggableElement);
547+
expect(draggableElement.style.cursor).not.to.be.ok;
548+
});
536549
});

0 commit comments

Comments
 (0)