@@ -3467,6 +3467,60 @@ describe('CdkDrag', () => {
3467
3467
} ) ) ;
3468
3468
3469
3469
} ) ;
3470
+
3471
+ describe ( 'with nested drags' , ( ) => {
3472
+ it ( 'should not move draggable container when dragging child (multitouch)' , fakeAsync ( ( ) => {
3473
+
3474
+ const fixture = createComponent ( NestedDragsComponent , [ ] , 10 ) ;
3475
+ fixture . detectChanges ( ) ;
3476
+
3477
+ // First finger drags container (less then threshold)
3478
+ startDraggingViaTouch ( fixture , fixture . componentInstance . container . nativeElement ) ;
3479
+ continueDraggingViaTouch ( fixture , 2 , 0 ) ;
3480
+
3481
+ // Second finger drags container
3482
+ startDraggingViaTouch ( fixture , fixture . componentInstance . container . nativeElement ) ;
3483
+ continueDraggingViaTouch ( fixture , 0 , 10 ) ;
3484
+ continueDraggingViaTouch ( fixture , 0 , 20 ) ;
3485
+
3486
+ // First finger releases
3487
+ stopDraggingViaTouch ( fixture , 0 , 20 ) ;
3488
+ // Second finger releases
3489
+ stopDraggingViaTouch ( fixture , 0 , 10 ) ;
3490
+
3491
+ // Container spies worked
3492
+ const containerDragStartedCount =
3493
+ fixture . componentInstance . containerDragStartedSpy . calls . count ( ) ;
3494
+ const containerDragMovedCount =
3495
+ fixture . componentInstance . containerDragMovedSpy . calls . count ( ) ;
3496
+ const containerDragReleasedCount =
3497
+ fixture . componentInstance . containerDragReleasedSpy . calls . count ( ) ;
3498
+
3499
+ expect ( containerDragStartedCount ) . toBeGreaterThan ( 0 ) ;
3500
+ expect ( containerDragMovedCount ) . toBeGreaterThan ( 0 ) ;
3501
+ expect ( containerDragReleasedCount ) . toBeGreaterThan ( 0 ) ;
3502
+
3503
+ // Drag item
3504
+ startDraggingViaTouch ( fixture , fixture . componentInstance . item . nativeElement ) ;
3505
+ continueDraggingViaTouch ( fixture , 20 , 20 ) ;
3506
+ continueDraggingViaTouch ( fixture , 40 , 40 ) ;
3507
+ stopDraggingViaTouch ( fixture , 60 , 60 ) ;
3508
+
3509
+ // Spies on item worked
3510
+ expect ( fixture . componentInstance . itemDragStartedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3511
+ expect ( fixture . componentInstance . itemDragMovedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3512
+ expect ( fixture . componentInstance . itemDragReleasedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3513
+
3514
+ // Spies on container stay intact
3515
+ expect ( fixture . componentInstance . containerDragStartedSpy )
3516
+ . toHaveBeenCalledTimes ( containerDragStartedCount ) ;
3517
+ expect ( fixture . componentInstance . containerDragMovedSpy )
3518
+ . toHaveBeenCalledTimes ( containerDragMovedCount ) ;
3519
+ expect ( fixture . componentInstance . containerDragReleasedSpy )
3520
+ . toHaveBeenCalledTimes ( containerDragReleasedCount ) ;
3521
+
3522
+ } ) ) ;
3523
+ } ) ;
3470
3524
} ) ;
3471
3525
3472
3526
@Component ( {
@@ -4063,6 +4117,56 @@ class WrappedDropContainerComponent {
4063
4117
@Input ( ) items : string [ ] ;
4064
4118
}
4065
4119
4120
+ @Component ( {
4121
+ styles : [ `
4122
+ :host {
4123
+ height: 400px;
4124
+ width: 400px;
4125
+ position: absolute;
4126
+ }
4127
+ .container {
4128
+ height: 200px;
4129
+ width: 200px;
4130
+ position: absolute;
4131
+ }
4132
+ .item {
4133
+ height: 50px;
4134
+ width: 50px;
4135
+ position: absolute;
4136
+ }
4137
+ ` ] ,
4138
+ template : `
4139
+ <div
4140
+ cdkDrag
4141
+ #container
4142
+ class="container"
4143
+ (cdkDragStarted)="containerDragStartedSpy($event)"
4144
+ (cdkDragMoved)="containerDragMovedSpy($event)"
4145
+ (cdkDragReleased)="containerDragReleasedSpy($event)"
4146
+ >
4147
+ <div
4148
+ cdkDrag
4149
+ class="item"
4150
+ #item
4151
+ (cdkDragStarted)="itemDragStartedSpy($event)"
4152
+ (cdkDragMoved)="itemDragMovedSpy($event)"
4153
+ (cdkDragReleased)="itemDragReleasedSpy($event)"
4154
+ >
4155
+ </div>
4156
+ </div>`
4157
+ } )
4158
+ class NestedDragsComponent {
4159
+ @ViewChild ( 'container' , { static : false } ) container : ElementRef ;
4160
+ @ViewChild ( 'item' , { static : false } ) item : ElementRef ;
4161
+
4162
+ containerDragStartedSpy = jasmine . createSpy ( 'container drag started spy' ) ;
4163
+ containerDragMovedSpy = jasmine . createSpy ( 'container drag moved spy' ) ;
4164
+ containerDragReleasedSpy = jasmine . createSpy ( 'container drag released spy' ) ;
4165
+ itemDragStartedSpy = jasmine . createSpy ( 'item drag started spy' ) ;
4166
+ itemDragMovedSpy = jasmine . createSpy ( 'item drag moved spy' ) ;
4167
+ itemDragReleasedSpy = jasmine . createSpy ( 'item drag released spy' ) ;
4168
+ }
4169
+
4066
4170
/**
4067
4171
* Drags an element to a position on the page using the mouse.
4068
4172
* @param fixture Fixture on which to run change detection.
@@ -4107,16 +4211,40 @@ function startDraggingViaMouse(fixture: ComponentFixture<any>,
4107
4211
*/
4108
4212
function dragElementViaTouch ( fixture : ComponentFixture < any > ,
4109
4213
element : Element , x : number , y : number ) {
4214
+ startDraggingViaTouch ( fixture , element ) ;
4215
+ continueDraggingViaTouch ( fixture , x , y ) ;
4216
+ stopDraggingViaTouch ( fixture , x , y ) ;
4217
+ }
4110
4218
4219
+ /**
4220
+ * @param fixture Fixture on which to run change detection.
4221
+ * @param element Element which is being dragged.
4222
+ */
4223
+ function startDraggingViaTouch ( fixture : ComponentFixture < any > ,
4224
+ element : Element ) {
4111
4225
dispatchTouchEvent ( element , 'touchstart' ) ;
4112
4226
fixture . detectChanges ( ) ;
4113
4227
4114
4228
dispatchTouchEvent ( document , 'touchmove' ) ;
4115
4229
fixture . detectChanges ( ) ;
4230
+ }
4116
4231
4232
+ /**
4233
+ * @param fixture Fixture on which to run change detection.
4234
+ * @param x Position along the x axis to which to drag the element.
4235
+ * @param y Position along the y axis to which to drag the element.
4236
+ */
4237
+ function continueDraggingViaTouch ( fixture : ComponentFixture < any > , x : number , y : number ) {
4117
4238
dispatchTouchEvent ( document , 'touchmove' , x , y ) ;
4118
4239
fixture . detectChanges ( ) ;
4240
+ }
4119
4241
4242
+ /**
4243
+ * @param fixture Fixture on which to run change detection.
4244
+ * @param x Position along the x axis to which to drag the element.
4245
+ * @param y Position along the y axis to which to drag the element.
4246
+ */
4247
+ function stopDraggingViaTouch ( fixture : ComponentFixture < any > , x : number , y : number ) {
4120
4248
dispatchTouchEvent ( document , 'touchend' , x , y ) ;
4121
4249
fixture . detectChanges ( ) ;
4122
4250
}
0 commit comments