Skip to content

Commit

Permalink
fix: set the resize cursor globally when resizing
Browse files Browse the repository at this point in the history
Fixes #70
  • Loading branch information
Matt Lewis committed Dec 26, 2017
1 parent 705a589 commit 71d5a05
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<style>
body {
min-height: 100vh;
}
</style>
<title>angular 4.0+ resizable element</title>
</head>
<body>
Expand Down
17 changes: 12 additions & 5 deletions src/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,16 @@ export class ResizableDirective implements OnInit, OnDestroy {
DEFAULT_RESIZE_CURSORS,
this.resizeCursors
);
const cursor: string = currentResize
? ''
: getResizeCursor(resizeEdges, resizeCursors);

this.renderer.setStyle(this.elm.nativeElement, 'cursor', cursor);
if (currentResize) {
const cursor: string = getResizeCursor(
currentResize.edges,
resizeCursors
);
this.renderer.setStyle(document.body, 'cursor', cursor);
} else {
const cursor: string = getResizeCursor(resizeEdges, resizeCursors);
this.renderer.setStyle(this.elm.nativeElement, 'cursor', cursor);
}
this.setElementClass(this.elm, RESIZE_ACTIVE_CLASS, !!currentResize);
this.setElementClass(
this.elm,
Expand Down Expand Up @@ -679,6 +684,8 @@ export class ResizableDirective implements OnInit, OnDestroy {
this.mouseup.subscribe(() => {
if (currentResize) {
this.renderer.removeClass(this.elm.nativeElement, RESIZE_ACTIVE_CLASS);
this.renderer.setStyle(document.body, 'cursor', '');
this.renderer.setStyle(this.elm.nativeElement, 'cursor', '');
this.zone.run(() => {
this.resizeEnd.emit({
edges: getEdgesDiff({
Expand Down
22 changes: 22 additions & 0 deletions test/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1399,4 +1399,26 @@ describe('resizable directive', () => {
}
});
});

it('should set the resize cursor on the body when resizing', () => {
const fixture: ComponentFixture<TestComponent> = createComponent();
fixture.componentInstance.enableGhostResize = false;
fixture.detectChanges();
const elm: HTMLElement =
fixture.componentInstance.resizable.elm.nativeElement;
triggerDomEvent('mousedown', elm, {
clientX: 100,
clientY: 200
});
triggerDomEvent('mousemove', elm, {
clientX: 101,
clientY: 200
});
expect(document.body.style.cursor).to.equal('nw-resize');
triggerDomEvent('mouseup', elm, {
clientX: 101,
clientY: 200
});
expect(document.body.style.cursor).to.equal('');
});
});

0 comments on commit 71d5a05

Please sign in to comment.