File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -1437,6 +1437,28 @@ describe('CdkDrag', () => {
1437
1437
} ) ;
1438
1438
} ) ) ;
1439
1439
1440
+ it ( 'should call the `enterPredicate` with the item and the container it is entering' ,
1441
+ fakeAsync ( ( ) => {
1442
+ const fixture = createComponent ( ConnectedDropZones ) ;
1443
+ fixture . detectChanges ( ) ;
1444
+
1445
+ const dropInstances = fixture . componentInstance . dropInstances . toArray ( ) ;
1446
+ const spy = jasmine . createSpy ( 'enterPredicate spy' ) . and . returnValue ( true ) ;
1447
+ const groups = fixture . componentInstance . groupedDragItems . slice ( ) ;
1448
+ const dragItem = groups [ 0 ] [ 1 ] ;
1449
+ const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
1450
+
1451
+ dropInstances [ 1 ] . enterPredicate = spy ;
1452
+ fixture . detectChanges ( ) ;
1453
+
1454
+ dragElementViaMouse ( fixture , dragItem . element . nativeElement ,
1455
+ targetRect . left + 1 , targetRect . top + 1 ) ;
1456
+ flush ( ) ;
1457
+ fixture . detectChanges ( ) ;
1458
+
1459
+ expect ( spy ) . toHaveBeenCalledWith ( dragItem , dropInstances [ 1 ] ) ;
1460
+ } ) ) ;
1461
+
1440
1462
it ( 'should be able to start dragging after an item has been transferred' , fakeAsync ( ( ) => {
1441
1463
const fixture = createComponent ( ConnectedDropZones ) ;
1442
1464
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -77,11 +77,12 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
77
77
@Input ( 'cdkDropLockAxis' ) lockAxis : 'x' | 'y' ;
78
78
79
79
/**
80
- * Function that is used to determine whether an item
81
- * is allowed to be moved into a drop container.
80
+ * Function that is used to determine whether an item is allowed to be moved
81
+ * into a drop container. The function will be called with the item that is
82
+ * being dragged and the container that it's being moved into.
82
83
*/
83
84
@Input ( 'cdkDropEnterPredicate' )
84
- enterPredicate : ( drag ? : CdkDrag , drop ? : CdkDrop ) => boolean = ( ) => true
85
+ enterPredicate : ( drag : CdkDrag , drop : CdkDrop ) => boolean = ( ) => true
85
86
86
87
/** Emits when the user drops an item inside the container. */
87
88
@Output ( 'cdkDropDropped' )
@@ -315,7 +316,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
315
316
const result = this . _positionCache . siblings
316
317
. find ( sibling => isInsideClientRect ( sibling . clientRect , x , y ) ) ;
317
318
318
- return result && result . drop . enterPredicate ( item , this ) ? result . drop : null ;
319
+ return result && result . drop . enterPredicate ( item , result . drop ) ? result . drop : null ;
319
320
}
320
321
321
322
/**
You can’t perform that action at this time.
0 commit comments