@@ -776,13 +776,55 @@ describe('CdkDrag', () => {
776776 currentIndex : 2 ,
777777 item : firstItem ,
778778 container : fixture . componentInstance . dropInstance ,
779- previousContainer : fixture . componentInstance . dropInstance
779+ previousContainer : fixture . componentInstance . dropInstance ,
780+ isPointerOverContainer : true
780781 } ) ;
781782
782783 expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
783784 . toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
784785 } ) ) ;
785786
787+ it ( 'should expose whether an item was dropped over a container' , fakeAsync ( ( ) => {
788+ const fixture = createComponent ( DraggableInDropZone ) ;
789+ fixture . detectChanges ( ) ;
790+ const dragItems = fixture . componentInstance . dragItems ;
791+ const firstItem = dragItems . first ;
792+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
793+
794+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
795+ thirdItemRect . left + 1 , thirdItemRect . top + 1 ) ;
796+ flush ( ) ;
797+ fixture . detectChanges ( ) ;
798+
799+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
800+
801+ const event : CdkDragDrop < any > =
802+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
803+
804+ expect ( event . isPointerOverContainer ) . toBe ( true ) ;
805+ } ) ) ;
806+
807+ it ( 'should expose whether an item was dropped outside of a container' , fakeAsync ( ( ) => {
808+ const fixture = createComponent ( DraggableInDropZone ) ;
809+ fixture . detectChanges ( ) ;
810+ const dragItems = fixture . componentInstance . dragItems ;
811+ const firstItem = dragItems . first ;
812+ const containerRect = fixture . componentInstance . dropInstance . element
813+ . nativeElement . getBoundingClientRect ( ) ;
814+
815+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
816+ containerRect . right + 10 , containerRect . bottom + 10 ) ;
817+ flush ( ) ;
818+ fixture . detectChanges ( ) ;
819+
820+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
821+
822+ const event : CdkDragDrop < any > =
823+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
824+
825+ expect ( event . isPointerOverContainer ) . toBe ( false ) ;
826+ } ) ) ;
827+
786828 it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
787829 const fixture = createComponent ( DraggableInDropZone ) ;
788830 fixture . detectChanges ( ) ;
@@ -841,7 +883,8 @@ describe('CdkDrag', () => {
841883 currentIndex : 0 ,
842884 item : firstItem ,
843885 container : fixture . componentInstance . dropInstance ,
844- previousContainer : fixture . componentInstance . dropInstance
886+ previousContainer : fixture . componentInstance . dropInstance ,
887+ isPointerOverContainer : false
845888 } ) ;
846889
847890 expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -898,7 +941,8 @@ describe('CdkDrag', () => {
898941 currentIndex : 2 ,
899942 item : firstItem ,
900943 container : fixture . componentInstance . dropInstance ,
901- previousContainer : fixture . componentInstance . dropInstance
944+ previousContainer : fixture . componentInstance . dropInstance ,
945+ isPointerOverContainer : true
902946 } ) ;
903947
904948 expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -937,7 +981,8 @@ describe('CdkDrag', () => {
937981 currentIndex : 2 ,
938982 item : firstItem ,
939983 container : fixture . componentInstance . dropInstance ,
940- previousContainer : fixture . componentInstance . dropInstance
984+ previousContainer : fixture . componentInstance . dropInstance ,
985+ isPointerOverContainer : true
941986 } ) ;
942987
943988 expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -972,7 +1017,8 @@ describe('CdkDrag', () => {
9721017 currentIndex : 0 ,
9731018 item : firstItem ,
9741019 container : fixture . componentInstance . dropInstance ,
975- previousContainer : fixture . componentInstance . dropInstance
1020+ previousContainer : fixture . componentInstance . dropInstance ,
1021+ isPointerOverContainer : false
9761022 } ) ;
9771023
9781024 expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -1808,7 +1854,8 @@ describe('CdkDrag', () => {
18081854 currentIndex : 3 ,
18091855 item,
18101856 container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
1811- previousContainer : fixture . componentInstance . dropInstances . first
1857+ previousContainer : fixture . componentInstance . dropInstances . first ,
1858+ isPointerOverContainer : true
18121859 } ) ;
18131860 } ) ) ;
18141861
@@ -1909,7 +1956,8 @@ describe('CdkDrag', () => {
19091956 currentIndex : 3 ,
19101957 item : groups [ 0 ] [ 1 ] ,
19111958 container : dropInstances [ 1 ] ,
1912- previousContainer : dropInstances [ 0 ]
1959+ previousContainer : dropInstances [ 0 ] ,
1960+ isPointerOverContainer : true
19131961 } ) ;
19141962 } ) ) ;
19151963
@@ -1938,7 +1986,8 @@ describe('CdkDrag', () => {
19381986 currentIndex : 1 ,
19391987 item : groups [ 0 ] [ 1 ] ,
19401988 container : dropInstances [ 0 ] ,
1941- previousContainer : dropInstances [ 0 ]
1989+ previousContainer : dropInstances [ 0 ] ,
1990+ isPointerOverContainer : false
19421991 } ) ;
19431992 } ) ) ;
19441993
@@ -1967,7 +2016,8 @@ describe('CdkDrag', () => {
19672016 currentIndex : 1 ,
19682017 item : groups [ 0 ] [ 1 ] ,
19692018 container : dropInstances [ 0 ] ,
1970- previousContainer : dropInstances [ 0 ]
2019+ previousContainer : dropInstances [ 0 ] ,
2020+ isPointerOverContainer : false
19712021 } ) ;
19722022 } ) ) ;
19732023
@@ -2089,7 +2139,8 @@ describe('CdkDrag', () => {
20892139 currentIndex : 3 ,
20902140 item : groups [ 0 ] [ 1 ] ,
20912141 container : dropInstances [ 1 ] ,
2092- previousContainer : dropInstances [ 0 ]
2142+ previousContainer : dropInstances [ 0 ] ,
2143+ isPointerOverContainer : true
20932144 } ) ;
20942145 } ) ) ;
20952146
@@ -2114,7 +2165,8 @@ describe('CdkDrag', () => {
21142165 currentIndex : 3 ,
21152166 item : groups [ 0 ] [ 1 ] ,
21162167 container : dropInstances [ 1 ] ,
2117- previousContainer : dropInstances [ 0 ]
2168+ previousContainer : dropInstances [ 0 ] ,
2169+ isPointerOverContainer : true
21182170 } ) ;
21192171 } ) ) ;
21202172
@@ -2144,7 +2196,8 @@ describe('CdkDrag', () => {
21442196 currentIndex : 3 ,
21452197 item : groups [ 0 ] [ 1 ] ,
21462198 container : dropInstances [ 1 ] ,
2147- previousContainer : dropInstances [ 0 ]
2199+ previousContainer : dropInstances [ 0 ] ,
2200+ isPointerOverContainer : true
21482201 } ) ;
21492202 } ) ) ;
21502203
@@ -2178,7 +2231,8 @@ describe('CdkDrag', () => {
21782231 currentIndex : 0 ,
21792232 item,
21802233 container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
2181- previousContainer : fixture . componentInstance . dropInstances . first
2234+ previousContainer : fixture . componentInstance . dropInstances . first ,
2235+ isPointerOverContainer : true
21822236 } ) ;
21832237
21842238 expect ( dropContainers [ 0 ] . contains ( item . element . nativeElement ) ) . toBe ( true ,
@@ -2667,7 +2721,7 @@ function dragElementViaMouse(fixture: ComponentFixture<any>,
26672721 dispatchMouseEvent ( document , 'mousemove' , x , y ) ;
26682722 fixture . detectChanges ( ) ;
26692723
2670- dispatchMouseEvent ( document , 'mouseup' ) ;
2724+ dispatchMouseEvent ( document , 'mouseup' , x , y ) ;
26712725 fixture . detectChanges ( ) ;
26722726}
26732727
@@ -2706,7 +2760,7 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
27062760 dispatchTouchEvent ( document , 'touchmove' , x , y ) ;
27072761 fixture . detectChanges ( ) ;
27082762
2709- dispatchTouchEvent ( document , 'touchend' ) ;
2763+ dispatchTouchEvent ( document , 'touchend' , x , y ) ;
27102764 fixture . detectChanges ( ) ;
27112765}
27122766
0 commit comments