Skip to content

Commit 101e3ff

Browse files
laisengmmalerba
authored andcommitted
fix(cdk/drag-drop): fix for recommended changes to code and tests cases
1 parent de05a67 commit 101e3ff

File tree

2 files changed

+7
-79
lines changed

2 files changed

+7
-79
lines changed

src/cdk/drag-drop/directives/drag.spec.ts

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -409,45 +409,12 @@ describe('CdkDrag', () => {
409409

410410
describe('mouse dragging when initial transform is none', () => {
411411
it('should drag an element freely to a particular position', fakeAsync(() => {
412-
const fixture = createComponent(StandaloneDraggableWithInitialTransformNone);
413-
fixture.detectChanges();
414-
const dragElement = fixture.componentInstance.dragElement.nativeElement;
415-
416-
expect(dragElement.style.transform).toBe('none');
417-
dragElementViaMouse(fixture, dragElement, 50, 100);
418-
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
419-
}));
420-
421-
it('should drag an SVG element freely to a particular position', fakeAsync(() => {
422-
const fixture = createComponent(StandaloneDraggableSvgWithInitialTransformNone);
412+
const fixture = createComponent(StandaloneDraggable);
423413
fixture.detectChanges();
424414
const dragElement = fixture.componentInstance.dragElement.nativeElement;
415+
dragElement.style.transform = 'none';
425416

426-
expect(dragElement.style.transform).toBe('none');
427417
dragElementViaMouse(fixture, dragElement, 50, 100);
428-
expect(dragElement.getAttribute('transform')).toBe('translate(50 100)');
429-
}));
430-
431-
it('should drag an SVG element freely to a particular position in SVG viewBox coordinates',
432-
fakeAsync(() => {
433-
const fixture = createComponent(StandaloneDraggableSvgWithViewBoxInitialTranformNone);
434-
fixture.detectChanges();
435-
const dragElement = fixture.componentInstance.dragElement.nativeElement;
436-
437-
expect(dragElement.style.transform).toBe('none');
438-
dragElementViaMouse(fixture, dragElement, 50, 100);
439-
expect(dragElement.getAttribute('transform')).toBe('translate(100 200)');
440-
}));
441-
});
442-
443-
describe('touch dragging when initial transform is none', () => {
444-
it('should drag an element freely to a particular position', fakeAsync(() => {
445-
const fixture = createComponent(StandaloneDraggableWithInitialTransformNone);
446-
fixture.detectChanges();
447-
const dragElement = fixture.componentInstance.dragElement.nativeElement;
448-
449-
expect(dragElement.style.transform).toBe('none');
450-
dragElementViaTouch(fixture, dragElement, 50, 100);
451418
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
452419
}));
453420
});
@@ -5981,21 +5948,6 @@ class StandaloneDraggable {
59815948
freeDragPosition?: {x: number, y: number};
59825949
}
59835950

5984-
@Component({
5985-
template: `
5986-
<div class="wrapper" style="width: 200px; height: 200px; background: green;">
5987-
<div
5988-
cdkDrag
5989-
#dragElement
5990-
style="transform: none; width: 100px; height: 100px; background: red;"></div>
5991-
</div>
5992-
`
5993-
})
5994-
class StandaloneDraggableWithInitialTransformNone {
5995-
@ViewChild('dragElement') dragElement: ElementRef<HTMLElement>;
5996-
@ViewChild(CdkDrag) dragInstance: CdkDrag;
5997-
}
5998-
59995951
@Component({
60005952
changeDetection: ChangeDetectionStrategy.OnPush,
60015953
template: `
@@ -6020,34 +5972,6 @@ class StandaloneDraggableSvg {
60205972
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
60215973
}
60225974

6023-
@Component({
6024-
template: `
6025-
<svg><g
6026-
cdkDrag
6027-
style="transform: none"
6028-
#dragElement>
6029-
<circle fill="red" r="50" cx="50" cy="50"/>
6030-
</g></svg>
6031-
`
6032-
})
6033-
class StandaloneDraggableSvgWithInitialTransformNone {
6034-
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
6035-
}
6036-
6037-
@Component({
6038-
template: `
6039-
<svg width="400px" height="400px" viewBox="0 0 800 800"><g
6040-
cdkDrag
6041-
style="transform: none"
6042-
#dragElement>
6043-
<circle fill="red" r="50" cx="50" cy="50"/>
6044-
</g></svg>
6045-
`
6046-
})
6047-
class StandaloneDraggableSvgWithViewBoxInitialTranformNone {
6048-
@ViewChild('dragElement') dragElement: ElementRef<SVGElement>;
6049-
}
6050-
60515975
@Component({
60525976
template: `
60535977
<svg width="400px" height="400px" viewBox="0 0 800 800"><g

src/cdk/drag-drop/drag-ref.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,12 @@ export class DragRef<T = any> {
12771277

12781278
// Cache the previous transform amount only after the first drag sequence, because
12791279
// we don't want our own transforms to stack on top of each other.
1280+
// Should be excluded none because none + translate3d(x, y, x) is invalid css
12801281
if (this._initialTransform == null) {
1281-
this._initialTransform = this._rootElement.style.transform || '';
1282+
this._initialTransform = this._rootElement.style.transform
1283+
&& this._rootElement.style.transform != 'none'
1284+
? this._rootElement.style.transform
1285+
: '';
12821286
}
12831287

12841288
// Preserve the previous `transform` value, if there was one. Note that we apply our own

0 commit comments

Comments
 (0)