Skip to content

Commit

Permalink
feat(disableResize): support completely disabling resizing an element
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
Matt Lewis committed Jun 25, 2016
1 parent 8025ed3 commit 9f9c54a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const getResizeCursor: Function = (edges: Edges): string => {
export class Resizable implements OnInit {

@Input() validateResize: Function;
@Input() disableResize: boolean = false;
@Output() onResizeStart: EventEmitter<Object> = new EventEmitter(false);
@Output() onResize: EventEmitter<Object> = new EventEmitter(false);
@Output() onResizeEnd: EventEmitter<Object> = new EventEmitter(false);
Expand Down Expand Up @@ -147,7 +148,7 @@ export class Resizable implements OnInit {
}
};

this.mousemove.subscribe(({mouseX, mouseY}) => {
this.mousemove.filter(() => !this.disableResize).subscribe(({mouseX, mouseY}) => {

const resizeEdges: Edges = getResizeEdges({mouseX, mouseY, elm: this.elm});
const cursor: string = getResizeCursor(resizeEdges);
Expand Down Expand Up @@ -189,7 +190,7 @@ export class Resizable implements OnInit {

});

this.mousedown.subscribe(({mouseX, mouseY}) => {
this.mousedown.filter(() => !this.disableResize).subscribe(({mouseX, mouseY}) => {
const edges: Edges = getResizeEdges({mouseX, mouseY, elm: this.elm});
if (Object.keys(edges).length > 0) {
if (currentResize) {
Expand Down
32 changes: 32 additions & 0 deletions test/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('resizable directive', () => {
[ngStyle]="style"
mwl-resizeable
[validateResize]="validate"
[disableResize]="disableResize"
(onResizeStart)="onResizeStart($event)"
(onResize)="onResize($event)"
(onResizeEnd)="onResizeEnd($event)">
Expand All @@ -48,6 +49,7 @@ describe('resizable directive', () => {
public onResize: jasmine.Spy = jasmine.createSpy('onResize');
public onResizeEnd: jasmine.Spy = jasmine.createSpy('onResizeEnd');
public validate: jasmine.Spy = jasmine.createSpy('validate');
public disableResize: boolean = false;

constructor() {
this.validate.and.returnValue(true);
Expand Down Expand Up @@ -736,4 +738,34 @@ describe('resizable directive', () => {
});
}));

it('should disable resizing of the element', async(() => {

componentPromise.then((fixture: ComponentFixture<TestCmp>) => {
const elm: HTMLElement = fixture.componentInstance.resizable.elm.nativeElement;
fixture.componentInstance.disableResize = true;
fixture.detectChanges();
triggerDomEvent('mousemove', elm, {
clientX: 100,
clientY: 210
});
expect(getComputedStyle(elm).cursor).toEqual('auto');
triggerDomEvent('mousedown', elm, {
clientX: 100,
clientY: 210
});
expect(fixture.componentInstance.onResizeStart).not.toHaveBeenCalled();
triggerDomEvent('mousemove', elm, {
clientX: 101,
clientY: 210
});
expect(fixture.componentInstance.onResize).not.toHaveBeenCalled();
triggerDomEvent('mouseup', elm, {
clientX: 101,
clientY: 210
});
expect(fixture.componentInstance.onResizeEnd).not.toHaveBeenCalled();
});

}));

});

0 comments on commit 9f9c54a

Please sign in to comment.