Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle translate3d transforms on resizable elements #122

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function getElementRect(
.map(property => style[property])
.find(value => !!value);
if (transform && transform.includes('translate')) {
translateX = transform.replace(/.*translate\((.*)px, (.*)px\).*/, '$1');
translateY = transform.replace(/.*translate\((.*)px, (.*)px\).*/, '$2');
translateX = transform.replace(/.*translate3?d?\(([0-9]*)px, ([0-9]*)px.*/, '$1');
translateY = transform.replace(/.*translate3?d?\(([0-9]*)px, ([0-9]*)px.*/, '$2');
}

if (ghostElementPositioning === 'absolute') {
Expand Down
25 changes: 25 additions & 0 deletions test/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,31 @@ describe('resizable directive', () => {
});
});

it('should respect the css transform with 3d property translate on the element', () => {
const fixture: ComponentFixture<TestComponent> = createComponent();
const elm: HTMLElement =
fixture.componentInstance.resizable.elm.nativeElement;
elm.style.transform = 'translate3d(10px, 20px, 0px)';
triggerDomEvent('mousedown', elm, {
clientX: 110,
clientY: 220
});
expect(fixture.componentInstance.resizeStart).to.have.been.calledWith({
edges: {
left: 0,
top: 0
},
rectangle: {
top: 200,
left: 100,
width: 300,
height: 150,
right: 400,
bottom: 350
}
});
});

it('should not allow negative resizes', () => {
const fixture: ComponentFixture<TestComponent> = createComponent();
const elm: HTMLElement =
Expand Down