@@ -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 ) ;
@@ -3485,7 +3522,7 @@ describe('CdkDrag', () => {
3485
3522
const fixture = createComponent ( DraggableInDropZone ) ;
3486
3523
fixture . detectChanges ( ) ;
3487
3524
3488
- const cleanup = makePageScrollable ( ) ;
3525
+ const cleanup = makeScrollable ( ) ;
3489
3526
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3490
3527
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3491
3528
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3506,7 +3543,7 @@ describe('CdkDrag', () => {
3506
3543
const fixture = createComponent ( DraggableInDropZone ) ;
3507
3544
fixture . detectChanges ( ) ;
3508
3545
3509
- const cleanup = makePageScrollable ( ) ;
3546
+ const cleanup = makeScrollable ( ) ;
3510
3547
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3511
3548
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3512
3549
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3529,7 +3566,7 @@ describe('CdkDrag', () => {
3529
3566
const fixture = createComponent ( DraggableInDropZone ) ;
3530
3567
fixture . detectChanges ( ) ;
3531
3568
3532
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3569
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3533
3570
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3534
3571
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3535
3572
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3550,7 +3587,7 @@ describe('CdkDrag', () => {
3550
3587
const fixture = createComponent ( DraggableInDropZone ) ;
3551
3588
fixture . detectChanges ( ) ;
3552
3589
3553
- const cleanup = makePageScrollable ( 'horizontal' ) ;
3590
+ const cleanup = makeScrollable ( 'horizontal' ) ;
3554
3591
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
3555
3592
const viewportRuler = TestBed . inject ( ViewportRuler ) ;
3556
3593
const viewportSize = viewportRuler . getViewportSize ( ) ;
@@ -3587,7 +3624,7 @@ describe('CdkDrag', () => {
3587
3624
list . style . margin = '0' ;
3588
3625
3589
3626
const listRect = list . getBoundingClientRect ( ) ;
3590
- const cleanup = makePageScrollable ( ) ;
3627
+ const cleanup = makeScrollable ( ) ;
3591
3628
3592
3629
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3593
3630
list . scrollTop = 50 ;
@@ -3625,7 +3662,7 @@ describe('CdkDrag', () => {
3625
3662
list . style . margin = '0' ;
3626
3663
3627
3664
const listRect = list . getBoundingClientRect ( ) ;
3628
- const cleanup = makePageScrollable ( ) ;
3665
+ const cleanup = makeScrollable ( ) ;
3629
3666
3630
3667
scrollTo ( 0 , viewportRuler . getViewportSize ( ) . height * 5 ) ;
3631
3668
list . scrollTop = 0 ;
@@ -4744,7 +4781,7 @@ describe('CdkDrag', () => {
4744
4781
fixture . detectChanges ( ) ;
4745
4782
4746
4783
// Make the page scrollable and scroll the items out of view.
4747
- const cleanup = makePageScrollable ( ) ;
4784
+ const cleanup = makeScrollable ( ) ;
4748
4785
scrollTo ( 0 , 4000 ) ;
4749
4786
dispatchFakeEvent ( document , 'scroll' ) ;
4750
4787
fixture . detectChanges ( ) ;
@@ -5984,11 +6021,13 @@ function getElementSibligsByPosition(element: Element, direction: 'top' | 'left'
5984
6021
* Adds a large element to the page in order to make it scrollable.
5985
6022
* @returns Function that should be used to clean up after the test is done.
5986
6023
*/
5987
- function makePageScrollable ( direction : 'vertical' | 'horizontal' = 'vertical' ) {
6024
+ function makeScrollable (
6025
+ direction : 'vertical' | 'horizontal' = 'vertical' ,
6026
+ element = document . body ) {
5988
6027
const veryTallElement = document . createElement ( 'div' ) ;
5989
6028
veryTallElement . style . width = direction === 'vertical' ? '100%' : '4000px' ;
5990
6029
veryTallElement . style . height = direction === 'vertical' ? '2000px' : '5px' ;
5991
- document . body . appendChild ( veryTallElement ) ;
6030
+ element . appendChild ( veryTallElement ) ;
5992
6031
5993
6032
return ( ) => {
5994
6033
scrollTo ( 0 , 0 ) ;
0 commit comments