File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -5447,6 +5447,28 @@ describe('CdkDrag', () => {
5447
5447
expect ( itemEnterEvent ) . toEqual ( expectedEvent ) ;
5448
5448
} ) ) ;
5449
5449
5450
+ it ( 'should not throw if dragging was interrupted as a result of the entered event' ,
5451
+ fakeAsync ( ( ) => {
5452
+ const fixture = createComponent ( ConnectedDropZones ) ;
5453
+ fixture . detectChanges ( ) ;
5454
+
5455
+ const groups = fixture . componentInstance . groupedDragItems ;
5456
+ const item = groups [ 0 ] [ 1 ] ;
5457
+ const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
5458
+
5459
+ fixture . componentInstance . enteredSpy . and . callFake ( ( ) => {
5460
+ fixture . componentInstance . todo = [ ] ;
5461
+ fixture . detectChanges ( ) ;
5462
+ } ) ;
5463
+
5464
+ expect ( ( ) => {
5465
+ dragElementViaMouse (
5466
+ fixture , item . element . nativeElement , targetRect . left + 1 , targetRect . top + 1 ) ;
5467
+ flush ( ) ;
5468
+ fixture . detectChanges ( ) ;
5469
+ } ) . not . toThrow ( ) ;
5470
+ } ) ) ;
5471
+
5450
5472
it ( 'should be able to drop into a new container after scrolling into view' , fakeAsync ( ( ) => {
5451
5473
const fixture = createComponent ( ConnectedDropZones ) ;
5452
5474
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ export class DragRef<T = any> {
151
151
* Whether the dragging sequence has been started. Doesn't
152
152
* necessarily mean that the element has been moved.
153
153
*/
154
- private _hasStartedDragging : boolean ;
154
+ private _hasStartedDragging = false ;
155
155
156
156
/** Whether the element has moved since the user started dragging it. */
157
157
private _hasMoved : boolean ;
@@ -982,10 +982,13 @@ export class DragRef<T = any> {
982
982
} ) ;
983
983
}
984
984
985
- this . _dropContainer ! . _startScrollingIfNecessary ( rawX , rawY ) ;
986
- this . _dropContainer ! . _sortItem ( this , x , y , this . _pointerDirectionDelta ) ;
987
- this . _applyPreviewTransform (
988
- x - this . _pickupPositionInElement . x , y - this . _pickupPositionInElement . y ) ;
985
+ // Dragging may have been interrupted as a result of the events above.
986
+ if ( this . isDragging ( ) ) {
987
+ this . _dropContainer ! . _startScrollingIfNecessary ( rawX , rawY ) ;
988
+ this . _dropContainer ! . _sortItem ( this , x , y , this . _pointerDirectionDelta ) ;
989
+ this . _applyPreviewTransform (
990
+ x - this . _pickupPositionInElement . x , y - this . _pickupPositionInElement . y ) ;
991
+ }
989
992
}
990
993
991
994
/**
You can’t perform that action at this time.
0 commit comments