@@ -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
{
@@ -3375,6 +3375,24 @@ describe('CdkDrag', () => {
3375
3375
cleanup ( ) ;
3376
3376
} ) ) ;
3377
3377
3378
+ it ( 'should be able to auto-scroll a parent container' , fakeAsync ( ( ) => {
3379
+ const fixture = createComponent ( DraggableInScrollableParentContainer ) ;
3380
+ fixture . detectChanges ( ) ;
3381
+ const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3382
+ const container = fixture . nativeElement . querySelector ( '.container' ) ;
3383
+ const containerRect = container . getBoundingClientRect ( ) ;
3384
+
3385
+ expect ( container . scrollTop ) . toBe ( 0 ) ;
3386
+
3387
+ startDraggingViaMouse ( fixture , item ) ;
3388
+ dispatchMouseEvent ( document , 'mousemove' ,
3389
+ containerRect . left + containerRect . width / 2 , containerRect . top + containerRect . height ) ;
3390
+ fixture . detectChanges ( ) ;
3391
+ tickAnimationFrames ( 20 ) ;
3392
+
3393
+ expect ( container . scrollTop ) . toBeGreaterThan ( 0 ) ;
3394
+ } ) ) ;
3395
+
3378
3396
it ( 'should pick up descendants inside of containers' , fakeAsync ( ( ) => {
3379
3397
const fixture = createComponent ( DraggableInDropZoneWithContainer ) ;
3380
3398
fixture . detectChanges ( ) ;
@@ -4659,6 +4677,30 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
4659
4677
}
4660
4678
}
4661
4679
4680
+ @Component ( {
4681
+ template : '<div class="container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>' ,
4682
+
4683
+ // Note that it needs a margin to ensure that it's not flush against the viewport
4684
+ // edge which will cause the viewport to scroll, rather than the list.
4685
+ styles : [ `
4686
+ .container {
4687
+ max-height: 200px;
4688
+ overflow: auto;
4689
+ margin: 10vw 0 0 10vw;
4690
+ }
4691
+ ` ]
4692
+ } )
4693
+ class DraggableInScrollableParentContainer extends DraggableInDropZone {
4694
+ constructor ( ) {
4695
+ super ( ) ;
4696
+
4697
+ for ( let i = 0 ; i < 60 ; i ++ ) {
4698
+ this . items . push ( { value : `Extra item ${ i } ` , height : ITEM_HEIGHT , margin : 0 } ) ;
4699
+ }
4700
+ }
4701
+ }
4702
+
4703
+
4662
4704
@Component ( {
4663
4705
// Note that we need the blank `ngSwitch` below to hit the code path that we're testing.
4664
4706
template : `
0 commit comments