@@ -96,7 +96,7 @@ describe('CdkDrag', () => {
96
96
const fixture = createComponent ( StandaloneDraggable ) ;
97
97
fixture . detectChanges ( ) ;
98
98
99
- const cleanup = makePageScrollable ( ) ;
99
+ const cleanup = makeScrollable ( ) ;
100
100
const dragElement = fixture . componentInstance . dragElement . nativeElement ;
101
101
102
102
scrollTo ( 0 , 500 ) ;
@@ -126,7 +126,7 @@ describe('CdkDrag', () => {
126
126
fixture . detectChanges ( ) ;
127
127
128
128
const dragElement = fixture . componentInstance . dragElement . nativeElement ;
129
- const cleanup = makePageScrollable ( ) ;
129
+ const cleanup = makeScrollable ( ) ;
130
130
131
131
scrollTo ( 0 , 500 ) ;
132
132
expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
@@ -256,7 +256,7 @@ describe('CdkDrag', () => {
256
256
fixture . detectChanges ( ) ;
257
257
258
258
const dragElement = fixture . componentInstance . dragElement . nativeElement ;
259
- const cleanup = makePageScrollable ( ) ;
259
+ const cleanup = makeScrollable ( ) ;
260
260
261
261
scrollTo ( 0 , 500 ) ;
262
262
expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
@@ -285,7 +285,7 @@ describe('CdkDrag', () => {
285
285
fixture . detectChanges ( ) ;
286
286
287
287
const dragElement = fixture . componentInstance . dragElement . nativeElement ;
288
- const cleanup = makePageScrollable ( ) ;
288
+ const cleanup = makeScrollable ( ) ;
289
289
290
290
scrollTo ( 0 , 500 ) ;
291
291
expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
@@ -2034,7 +2034,7 @@ describe('CdkDrag', () => {
2034
2034
2035
2035
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2036
2036
const list = fixture . componentInstance . dropInstance . element . nativeElement ;
2037
- const cleanup = makePageScrollable ( ) ;
2037
+ const cleanup = makeScrollable ( ) ;
2038
2038
scrollTo ( 0 , 10 ) ;
2039
2039
let listRect = list . getBoundingClientRect ( ) ; // Note that we need to measure after scrolling.
2040
2040
@@ -2060,6 +2060,43 @@ describe('CdkDrag', () => {
2060
2060
cleanup ( ) ;
2061
2061
} ) ) ;
2062
2062
2063
+ it ( 'should update the boundary if a parent is scrolled while dragging' , fakeAsync ( ( ) => {
2064
+ const fixture = createComponent ( DraggableInScrollableParentContainer ) ;
2065
+ fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
2066
+ fixture . detectChanges ( ) ;
2067
+
2068
+ const container : HTMLElement = fixture . nativeElement . querySelector ( '.container' ) ;
2069
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2070
+ const list = fixture . componentInstance . dropInstance . element . nativeElement ;
2071
+ const cleanup = makeScrollable ( 'vertical' , container ) ;
2072
+ container . scrollTop = 10 ;
2073
+ let listRect = list . getBoundingClientRect ( ) ; // Note that we need to measure after scrolling.
2074
+
2075
+ startDraggingViaMouse ( fixture , item ) ;
2076
+ startDraggingViaMouse ( fixture , item , listRect . right , listRect . bottom ) ;
2077
+ flush ( ) ;
2078
+ dispatchMouseEvent ( document , 'mousemove' , listRect . right , listRect . bottom ) ;
2079
+ fixture . detectChanges ( ) ;
2080
+
2081
+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
2082
+ let previewRect = preview . getBoundingClientRect ( ) ;
2083
+
2084
+ // Different browsers round the scroll position differently so
2085
+ // assert that the offsets are within a pixel of each other.
2086
+ expect ( Math . abs ( previewRect . bottom - listRect . bottom ) ) . toBeLessThan ( 2 ) ;
2087
+
2088
+ container . scrollTop = 0 ;
2089
+ dispatchFakeEvent ( container , 'scroll' ) ;
2090
+ fixture . detectChanges ( ) ;
2091
+ listRect = list . getBoundingClientRect ( ) ; // We need to update these since we've scrolled.
2092
+ dispatchMouseEvent ( document , 'mousemove' , listRect . right , listRect . bottom ) ;
2093
+ fixture . detectChanges ( ) ;
2094
+ previewRect = preview . getBoundingClientRect ( ) ;
2095
+
2096
+ expect ( Math . abs ( previewRect . bottom - listRect . bottom ) ) . toBeLessThan ( 2 ) ;
2097
+ cleanup ( ) ;
2098
+ } ) ) ;
2099
+
2063
2100
it ( 'should clear the id from the preview' , fakeAsync ( ( ) => {
2064
2101
const fixture = createComponent ( DraggableInDropZone ) ;
2065
2102
fixture . detectChanges ( ) ;
@@ -2375,7 +2412,7 @@ describe('CdkDrag', () => {
2375
2412
fakeAsync ( ( ) => {
2376
2413
const fixture = createComponent ( DraggableInDropZone ) ;
2377
2414
fixture . detectChanges ( ) ;
2378
- const cleanup = makePageScrollable ( ) ;
2415
+ const cleanup = makeScrollable ( ) ;
2379
2416
2380
2417
scrollTo ( 0 , 500 ) ;
2381
2418
assertDownwardSorting ( fixture , fixture . componentInstance . dragItems . map ( item => {
@@ -2396,7 +2433,7 @@ describe('CdkDrag', () => {
2396
2433
fakeAsync ( ( ) => {
2397
2434
const fixture = createComponent ( DraggableInDropZone ) ;
2398
2435
fixture . detectChanges ( ) ;
2399
- const cleanup = makePageScrollable ( ) ;
2436
+ const cleanup = makeScrollable ( ) ;
2400
2437
2401
2438
scrollTo ( 0 , 500 ) ;
2402
2439
assertUpwardSorting ( fixture , fixture . componentInstance . dragItems . map ( item => {
@@ -2893,7 +2930,7 @@ describe('CdkDrag', () => {
2893
2930
it ( 'should keep the preview next to the trigger if the page was scrolled' , fakeAsync ( ( ) => {
2894
2931
const fixture = createComponent ( DraggableInDropZoneWithCustomPreview ) ;
2895
2932
fixture . detectChanges ( ) ;
2896
- const cleanup = makePageScrollable ( ) ;
2933
+ const cleanup = makeScrollable ( ) ;
2897
2934
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2898
2935
2899
2936
startDraggingViaMouse ( fixture , item , 50 , 50 ) ;
@@ -3468,7 +3505,7 @@ describe('CdkDrag', () => {
3468
3505
const fixture = createComponent ( DraggableInDropZone ) ;
3469
3506
fixture . detectChanges ( ) ;
3470
3507
3471
- const cleanup = makePageScrollable ( ) ;
3508
+ const cleanup = makeScrollable ( ) ;
3472
3509
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3473
3510
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3474
3511
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3489,7 +3526,7 @@ describe('CdkDrag', () => {
3489
3526
const fixture = createComponent ( DraggableInDropZone ) ;
3490
3527
fixture . detectChanges ( ) ;
3491
3528
3492
- const cleanup = makePageScrollable ( ) ;
3529
+ const cleanup = makeScrollable ( ) ;
3493
3530
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3494
3531
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3495
3532
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3512,7 +3549,7 @@ describe('CdkDrag', () => {
3512
3549
const fixture = createComponent ( DraggableInDropZone ) ;
3513
3550
fixture . detectChanges ( ) ;
3514
3551
3515
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3552
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3516
3553
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3517
3554
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3518
3555
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3533,7 +3570,7 @@ describe('CdkDrag', () => {
3533
3570
const fixture = createComponent ( DraggableInDropZone ) ;
3534
3571
fixture . detectChanges ( ) ;
3535
3572
3536
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3573
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3537
3574
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3538
3575
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3539
3576
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3570,7 +3607,7 @@ describe('CdkDrag', () => {
3570
3607
list . style . margin = '0' ;
3571
3608
3572
3609
const listRect = list . getBoundingClientRect ( ) ;
3573
- const cleanup = makePageScrollable ( ) ;
3610
+ const cleanup = makeScrollable ( ) ;
3574
3611
3575
3612
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3576
3613
list . scrollTop = 50 ;
@@ -3608,7 +3645,7 @@ describe('CdkDrag', () => {
3608
3645
list . style . margin = '0' ;
3609
3646
3610
3647
const listRect = list . getBoundingClientRect ( ) ;
3611
- const cleanup = makePageScrollable ( ) ;
3648
+ const cleanup = makeScrollable ( ) ;
3612
3649
3613
3650
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3614
3651
list . scrollTop = 0 ;
@@ -4684,7 +4721,7 @@ describe('CdkDrag', () => {
4684
4721
fixture . detectChanges ( ) ;
4685
4722
4686
4723
// Make the page scrollable and scroll the items out of view.
4687
- const cleanup = makePageScrollable ( ) ;
4724
+ const cleanup = makeScrollable ( ) ;
4688
4725
scrollTo ( 0 , 4000 ) ;
4689
4726
dispatchFakeEvent ( document , 'scroll' ) ;
4690
4727
fixture . detectChanges ( ) ;
@@ -5890,11 +5927,13 @@ function getElementSibligsByPosition(element: Element, direction: 'top' | 'left'
5890
5927
* Adds a large element to the page in order to make it scrollable.
5891
5928
* @returns Function that should be used to clean up after the test is done.
5892
5929
*/
5893
- function makePageScrollable ( direction : 'vertical' | 'horizontal' = 'vertical' ) {
5930
+ function makeScrollable (
5931
+ direction : 'vertical' | 'horizontal' = 'vertical' ,
5932
+ element = document . body ) {
5894
5933
const veryTallElement = document . createElement ( 'div' ) ;
5895
5934
veryTallElement . style . width = direction === 'vertical' ? '100%' : '4000px' ;
5896
5935
veryTallElement . style . height = direction === 'vertical' ? '2000px' : '5px' ;
5897
- document . body . appendChild ( veryTallElement ) ;
5936
+ element . appendChild ( veryTallElement ) ;
5898
5937
5899
5938
return ( ) => {
5900
5939
scrollTo ( 0 , 0 ) ;
0 commit comments