@@ -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,40 @@ 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
+ expect ( Math . floor ( previewRect . bottom ) ) . toBe ( Math . floor ( listRect . bottom ) ) ;
2084
+
2085
+ container . scrollTop = 0 ;
2086
+ dispatchFakeEvent ( container , 'scroll' ) ;
2087
+ fixture . detectChanges ( ) ;
2088
+ listRect = list . getBoundingClientRect ( ) ; // We need to update these since we've scrolled.
2089
+ dispatchMouseEvent ( document , 'mousemove' , listRect . right , listRect . bottom ) ;
2090
+ fixture . detectChanges ( ) ;
2091
+ previewRect = preview . getBoundingClientRect ( ) ;
2092
+
2093
+ expect ( Math . floor ( previewRect . bottom ) ) . toBe ( Math . floor ( listRect . bottom ) ) ;
2094
+ cleanup ( ) ;
2095
+ } ) ) ;
2096
+
2063
2097
it ( 'should clear the id from the preview' , fakeAsync ( ( ) => {
2064
2098
const fixture = createComponent ( DraggableInDropZone ) ;
2065
2099
fixture . detectChanges ( ) ;
@@ -2375,7 +2409,7 @@ describe('CdkDrag', () => {
2375
2409
fakeAsync ( ( ) => {
2376
2410
const fixture = createComponent ( DraggableInDropZone ) ;
2377
2411
fixture . detectChanges ( ) ;
2378
- const cleanup = makePageScrollable ( ) ;
2412
+ const cleanup = makeScrollable ( ) ;
2379
2413
2380
2414
scrollTo ( 0 , 500 ) ;
2381
2415
assertDownwardSorting ( fixture , fixture . componentInstance . dragItems . map ( item => {
@@ -2396,7 +2430,7 @@ describe('CdkDrag', () => {
2396
2430
fakeAsync ( ( ) => {
2397
2431
const fixture = createComponent ( DraggableInDropZone ) ;
2398
2432
fixture . detectChanges ( ) ;
2399
- const cleanup = makePageScrollable ( ) ;
2433
+ const cleanup = makeScrollable ( ) ;
2400
2434
2401
2435
scrollTo ( 0 , 500 ) ;
2402
2436
assertUpwardSorting ( fixture , fixture . componentInstance . dragItems . map ( item => {
@@ -2893,7 +2927,7 @@ describe('CdkDrag', () => {
2893
2927
it ( 'should keep the preview next to the trigger if the page was scrolled' , fakeAsync ( ( ) => {
2894
2928
const fixture = createComponent ( DraggableInDropZoneWithCustomPreview ) ;
2895
2929
fixture . detectChanges ( ) ;
2896
- const cleanup = makePageScrollable ( ) ;
2930
+ const cleanup = makeScrollable ( ) ;
2897
2931
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2898
2932
2899
2933
startDraggingViaMouse ( fixture , item , 50 , 50 ) ;
@@ -3468,7 +3502,7 @@ describe('CdkDrag', () => {
3468
3502
const fixture = createComponent ( DraggableInDropZone ) ;
3469
3503
fixture . detectChanges ( ) ;
3470
3504
3471
- const cleanup = makePageScrollable ( ) ;
3505
+ const cleanup = makeScrollable ( ) ;
3472
3506
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3473
3507
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3474
3508
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3489,7 +3523,7 @@ describe('CdkDrag', () => {
3489
3523
const fixture = createComponent ( DraggableInDropZone ) ;
3490
3524
fixture . detectChanges ( ) ;
3491
3525
3492
- const cleanup = makePageScrollable ( ) ;
3526
+ const cleanup = makeScrollable ( ) ;
3493
3527
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3494
3528
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3495
3529
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3512,7 +3546,7 @@ describe('CdkDrag', () => {
3512
3546
const fixture = createComponent ( DraggableInDropZone ) ;
3513
3547
fixture . detectChanges ( ) ;
3514
3548
3515
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3549
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3516
3550
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3517
3551
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3518
3552
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3533,7 +3567,7 @@ describe('CdkDrag', () => {
3533
3567
const fixture = createComponent ( DraggableInDropZone ) ;
3534
3568
fixture . detectChanges ( ) ;
3535
3569
3536
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3570
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3537
3571
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3538
3572
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3539
3573
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3570,7 +3604,7 @@ describe('CdkDrag', () => {
3570
3604
list . style . margin = '0' ;
3571
3605
3572
3606
const listRect = list . getBoundingClientRect ( ) ;
3573
- const cleanup = makePageScrollable ( ) ;
3607
+ const cleanup = makeScrollable ( ) ;
3574
3608
3575
3609
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3576
3610
list . scrollTop = 50 ;
@@ -3608,7 +3642,7 @@ describe('CdkDrag', () => {
3608
3642
list . style . margin = '0' ;
3609
3643
3610
3644
const listRect = list . getBoundingClientRect ( ) ;
3611
- const cleanup = makePageScrollable ( ) ;
3645
+ const cleanup = makeScrollable ( ) ;
3612
3646
3613
3647
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3614
3648
list . scrollTop = 0 ;
@@ -4684,7 +4718,7 @@ describe('CdkDrag', () => {
4684
4718
fixture . detectChanges ( ) ;
4685
4719
4686
4720
// Make the page scrollable and scroll the items out of view.
4687
- const cleanup = makePageScrollable ( ) ;
4721
+ const cleanup = makeScrollable ( ) ;
4688
4722
scrollTo ( 0 , 4000 ) ;
4689
4723
dispatchFakeEvent ( document , 'scroll' ) ;
4690
4724
fixture . detectChanges ( ) ;
@@ -5890,11 +5924,13 @@ function getElementSibligsByPosition(element: Element, direction: 'top' | 'left'
5890
5924
* Adds a large element to the page in order to make it scrollable.
5891
5925
* @returns Function that should be used to clean up after the test is done.
5892
5926
*/
5893
- function makePageScrollable ( direction : 'vertical' | 'horizontal' = 'vertical' ) {
5927
+ function makeScrollable (
5928
+ direction : 'vertical' | 'horizontal' = 'vertical' ,
5929
+ element = document . body ) {
5894
5930
const veryTallElement = document . createElement ( 'div' ) ;
5895
5931
veryTallElement . style . width = direction === 'vertical' ? '100%' : '4000px' ;
5896
5932
veryTallElement . style . height = direction === 'vertical' ? '2000px' : '5px' ;
5897
- document . body . appendChild ( veryTallElement ) ;
5933
+ element . appendChild ( veryTallElement ) ;
5898
5934
5899
5935
return ( ) => {
5900
5936
scrollTo ( 0 , 0 ) ;
0 commit comments