@@ -23,7 +23,7 @@ import {
23
23
} from '@angular/core' ;
24
24
import { TestBed , ComponentFixture , fakeAsync , flush , tick } from '@angular/core/testing' ;
25
25
import { DOCUMENT } from '@angular/common' ;
26
- import { ViewportRuler } from '@angular/cdk/scrolling' ;
26
+ import { ViewportRuler , ScrollingModule } from '@angular/cdk/scrolling' ;
27
27
import { _supportsShadowDom } from '@angular/cdk/platform' ;
28
28
import { of as observableOf } from 'rxjs' ;
29
29
@@ -47,7 +47,7 @@ describe('CdkDrag', () => {
47
47
extraDeclarations : Type < any > [ ] = [ ] ) : ComponentFixture < T > {
48
48
TestBed
49
49
. configureTestingModule ( {
50
- imports : [ DragDropModule ] ,
50
+ imports : [ DragDropModule , ScrollingModule ] ,
51
51
declarations : [ componentType , PassthroughComponent , ...extraDeclarations ] ,
52
52
providers : [
53
53
{
@@ -3411,6 +3411,24 @@ describe('CdkDrag', () => {
3411
3411
cleanup ( ) ;
3412
3412
} ) ) ;
3413
3413
3414
+ it ( 'should be able to auto-scroll a parent container' , fakeAsync ( ( ) => {
3415
+ const fixture = createComponent ( DraggableInScrollableParentContainer ) ;
3416
+ fixture . detectChanges ( ) ;
3417
+ const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3418
+ const container = fixture . nativeElement . querySelector ( '.container' ) ;
3419
+ const containerRect = container . getBoundingClientRect ( ) ;
3420
+
3421
+ expect ( container . scrollTop ) . toBe ( 0 ) ;
3422
+
3423
+ startDraggingViaMouse ( fixture , item ) ;
3424
+ dispatchMouseEvent ( document , 'mousemove' ,
3425
+ containerRect . left + containerRect . width / 2 , containerRect . top + containerRect . height ) ;
3426
+ fixture . detectChanges ( ) ;
3427
+ tickAnimationFrames ( 20 ) ;
3428
+
3429
+ expect ( container . scrollTop ) . toBeGreaterThan ( 0 ) ;
3430
+ } ) ) ;
3431
+
3414
3432
it ( 'should pick up descendants inside of containers' , fakeAsync ( ( ) => {
3415
3433
const fixture = createComponent ( DraggableInDropZoneWithContainer ) ;
3416
3434
fixture . detectChanges ( ) ;
@@ -4695,6 +4713,30 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
4695
4713
}
4696
4714
}
4697
4715
4716
+ @Component ( {
4717
+ template : '<div class="container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>' ,
4718
+
4719
+ // Note that it needs a margin to ensure that it's not flush against the viewport
4720
+ // edge which will cause the viewport to scroll, rather than the list.
4721
+ styles : [ `
4722
+ .container {
4723
+ max-height: 200px;
4724
+ overflow: auto;
4725
+ margin: 10vw 0 0 10vw;
4726
+ }
4727
+ ` ]
4728
+ } )
4729
+ class DraggableInScrollableParentContainer extends DraggableInDropZone {
4730
+ constructor ( ) {
4731
+ super ( ) ;
4732
+
4733
+ for ( let i = 0 ; i < 60 ; i ++ ) {
4734
+ this . items . push ( { value : `Extra item ${ i } ` , height : ITEM_HEIGHT , margin : 0 } ) ;
4735
+ }
4736
+ }
4737
+ }
4738
+
4739
+
4698
4740
@Component ( {
4699
4741
// Note that we need the blank `ngSwitch` below to hit the code path that we're testing.
4700
4742
template : `
0 commit comments