@@ -2169,7 +2169,7 @@ describe('CdkDrag', () => {
2169
2169
fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
2170
2170
fixture . detectChanges ( ) ;
2171
2171
2172
- const container : HTMLElement = fixture . nativeElement . querySelector ( '.container' ) ;
2172
+ const container : HTMLElement = fixture . nativeElement . querySelector ( '.scroll- container' ) ;
2173
2173
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2174
2174
const list = fixture . componentInstance . dropInstance . element . nativeElement ;
2175
2175
const cleanup = makeScrollable ( 'vertical' , container ) ;
@@ -3889,7 +3889,7 @@ describe('CdkDrag', () => {
3889
3889
const fixture = createComponent ( DraggableInScrollableParentContainer ) ;
3890
3890
fixture . detectChanges ( ) ;
3891
3891
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3892
- const container = fixture . nativeElement . querySelector ( '.container' ) ;
3892
+ const container = fixture . nativeElement . querySelector ( '.scroll- container' ) ;
3893
3893
const containerRect = container . getBoundingClientRect ( ) ;
3894
3894
3895
3895
expect ( container . scrollTop ) . toBe ( 0 ) ;
@@ -5519,7 +5519,7 @@ class StandaloneDraggableWithMultipleHandles {
5519
5519
const DROP_ZONE_FIXTURE_TEMPLATE = `
5520
5520
<div
5521
5521
cdkDropList
5522
- class="drop-list"
5522
+ class="drop-list scroll-container "
5523
5523
style="width: 100px; background: pink;"
5524
5524
[id]="dropZoneId"
5525
5525
[cdkDropListData]="items"
@@ -5539,7 +5539,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
5539
5539
` ;
5540
5540
5541
5541
@Component ( { template : DROP_ZONE_FIXTURE_TEMPLATE } )
5542
- class DraggableInDropZone {
5542
+ class DraggableInDropZone implements AfterViewInit {
5543
5543
@ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5544
5544
@ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
5545
5545
items = [
@@ -5556,6 +5556,15 @@ class DraggableInDropZone {
5556
5556
moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
5557
5557
} ) ;
5558
5558
startedSpy = jasmine . createSpy ( 'started spy' ) ;
5559
+
5560
+ constructor ( protected _elementRef : ElementRef ) { }
5561
+
5562
+ ngAfterViewInit ( ) {
5563
+ // Firefox preserves the `scrollTop` value from previous similar containers. This
5564
+ // could throw off test assertions and result in flaky results.
5565
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=959812.
5566
+ this . _elementRef . nativeElement . querySelector ( '.scroll-container' ) . scrollTop = 0 ;
5567
+ }
5559
5568
}
5560
5569
5561
5570
@Component ( {
@@ -5579,8 +5588,8 @@ class DraggableInOnPushDropZone extends DraggableInDropZone {}
5579
5588
` ]
5580
5589
} )
5581
5590
class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
5582
- constructor ( ) {
5583
- super ( ) ;
5591
+ constructor ( elementRef : ElementRef ) {
5592
+ super ( elementRef ) ;
5584
5593
5585
5594
for ( let i = 0 ; i < 60 ; i ++ ) {
5586
5595
this . items . push ( { value : `Extra item ${ i } ` , height : ITEM_HEIGHT , margin : 0 } ) ;
@@ -5589,21 +5598,21 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
5589
5598
}
5590
5599
5591
5600
@Component ( {
5592
- template : '<div class="container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>' ,
5601
+ template : '<div class="scroll- container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>' ,
5593
5602
5594
5603
// Note that it needs a margin to ensure that it's not flush against the viewport
5595
5604
// edge which will cause the viewport to scroll, rather than the list.
5596
5605
styles : [ `
5597
- .container {
5606
+ .scroll- container {
5598
5607
max-height: 200px;
5599
5608
overflow: auto;
5600
5609
margin: 10vw 0 0 10vw;
5601
5610
}
5602
5611
` ]
5603
5612
} )
5604
5613
class DraggableInScrollableParentContainer extends DraggableInDropZone {
5605
- constructor ( ) {
5606
- super ( ) ;
5614
+ constructor ( elementRef : ElementRef ) {
5615
+ super ( elementRef ) ;
5607
5616
5608
5617
for ( let i = 0 ; i < 60 ; i ++ ) {
5609
5618
this . items . push ( { value : `Extra item ${ i } ` , height : ITEM_HEIGHT , margin : 0 } ) ;
@@ -5617,7 +5626,7 @@ class DraggableInScrollableParentContainer extends DraggableInDropZone {
5617
5626
template : `
5618
5627
<div
5619
5628
cdkDropList
5620
- class="drop-list"
5629
+ class="drop-list scroll-container "
5621
5630
style="width: 100px; background: pink;"
5622
5631
[id]="dropZoneId"
5623
5632
[cdkDropListData]="items"
@@ -5656,7 +5665,7 @@ const HORIZONTAL_FIXTURE_STYLES = `
5656
5665
5657
5666
const HORIZONTAL_FIXTURE_TEMPLATE = `
5658
5667
<div
5659
- class="drop-list"
5668
+ class="drop-list scroll-container "
5660
5669
cdkDropList
5661
5670
cdkDropListOrientation="horizontal"
5662
5671
[cdkDropListData]="items"
@@ -5675,7 +5684,7 @@ const HORIZONTAL_FIXTURE_TEMPLATE = `
5675
5684
styles : [ HORIZONTAL_FIXTURE_STYLES ] ,
5676
5685
template : HORIZONTAL_FIXTURE_TEMPLATE
5677
5686
} )
5678
- class DraggableInHorizontalDropZone {
5687
+ class DraggableInHorizontalDropZone implements AfterViewInit {
5679
5688
@ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5680
5689
@ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
5681
5690
items = [
@@ -5688,6 +5697,15 @@ class DraggableInHorizontalDropZone {
5688
5697
droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
5689
5698
moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
5690
5699
} ) ;
5700
+
5701
+ constructor ( protected _elementRef : ElementRef ) { }
5702
+
5703
+ ngAfterViewInit ( ) {
5704
+ // Firefox preserves the `scrollLeft` value from previous similar containers. This
5705
+ // could throw off test assertions and result in flaky results.
5706
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=959812.
5707
+ this . _elementRef . nativeElement . querySelector ( '.scroll-container' ) . scrollLeft = 0 ;
5708
+ }
5691
5709
}
5692
5710
5693
5711
@@ -5706,8 +5724,8 @@ class DraggableInHorizontalDropZone {
5706
5724
` ]
5707
5725
} )
5708
5726
class DraggableInScrollableHorizontalDropZone extends DraggableInHorizontalDropZone {
5709
- constructor ( ) {
5710
- super ( ) ;
5727
+ constructor ( elementRef : ElementRef ) {
5728
+ super ( elementRef ) ;
5711
5729
5712
5730
for ( let i = 0 ; i < 60 ; i ++ ) {
5713
5731
this . items . push ( { value : `Extra item ${ i } ` , width : ITEM_WIDTH , margin : 0 } ) ;
@@ -6142,6 +6160,7 @@ class ConnectedWrappedDropZones {
6142
6160
@Component ( {
6143
6161
template : `
6144
6162
<div
6163
+ class="drop-list scroll-container"
6145
6164
cdkDropList
6146
6165
style="width: 100px; background: pink;"
6147
6166
[id]="dropZoneId"
@@ -6162,11 +6181,12 @@ class ConnectedWrappedDropZones {
6162
6181
`
6163
6182
} )
6164
6183
class DraggableWithCanvasInDropZone extends DraggableInDropZone implements AfterViewInit {
6165
- constructor ( private _elementRef : ElementRef < HTMLElement > ) {
6166
- super ( ) ;
6184
+ constructor ( elementRef : ElementRef < HTMLElement > ) {
6185
+ super ( elementRef ) ;
6167
6186
}
6168
6187
6169
6188
ngAfterViewInit ( ) {
6189
+ super . ngAfterViewInit ( ) ;
6170
6190
const canvases = this . _elementRef . nativeElement . querySelectorAll ( 'canvas' ) ;
6171
6191
6172
6192
// Add a circle to all the canvases.
@@ -6183,6 +6203,7 @@ class DraggableWithCanvasInDropZone extends DraggableInDropZone implements After
6183
6203
@Component ( {
6184
6204
template : `
6185
6205
<div
6206
+ class="drop-list scroll-container"
6186
6207
cdkDropList
6187
6208
style="width: 100px; background: pink;"
6188
6209
[id]="dropZoneId"
@@ -6413,6 +6434,7 @@ class DraggableWithAlternateRootAndSelfHandle {
6413
6434
template : `
6414
6435
<div
6415
6436
cdkDropList
6437
+ class="drop-list scroll-container"
6416
6438
style="width: 100px; background: pink;"
6417
6439
[id]="dropZoneId"
6418
6440
[cdkDropListData]="items"
0 commit comments