Skip to content

Commit

Permalink
fix(onResizeEnd): call with co-ordinates of last valid resize rather …
Browse files Browse the repository at this point in the history
…than where the mouse up event w
  • Loading branch information
Matt Lewis committed Jun 25, 2016
1 parent 149c1a4 commit eb314fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ export class Resizable implements OnInit {
}
});

this.mouseup.subscribe(({mouseX, mouseY}) => {
this.mouseup.subscribe(() => {
if (currentResize) {
this.onResizeEnd.emit({
edges: currentResize.edges,
rectangle: getNewBoundingRectangle(
currentResize.startingRect,
currentResize.edges,
mouseX - currentResize.startCoords.mouseX,
mouseY - currentResize.startCoords.mouseY
this.elm.nativeElement.getBoundingClientRect(),
{},
0,
0
)
});
resetElementStyles();
Expand Down
31 changes: 31 additions & 0 deletions test/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,35 @@ describe('resizable directive', () => {
});
}));

it('should fire the resize end event with the last valid bounding rectangle', async(() => {
componentPromise.then((fixture: ComponentFixture<TestCmp>) => {
const elm: HTMLElement = fixture.componentInstance.resizable.elm.nativeElement;
triggerDomEvent('mousedown', elm, {
clientX: 100,
clientY: 210
});
triggerDomEvent('mousemove', elm, {
clientX: 99,
clientY: 210
});
triggerDomEvent('mouseup', elm, {
clientX: 500,
clientY: 210
});
expect(fixture.componentInstance.onResizeEnd).toHaveBeenCalledWith({
edges: {
left: true
},
rectangle: {
top: 200,
left: 99,
width: 301,
height: 150,
right: 400,
bottom: 350
}
});
});
}));

});

0 comments on commit eb314fd

Please sign in to comment.