99 ViewChild ,
1010 ViewChildren ,
1111 ViewEncapsulation ,
12+ ChangeDetectionStrategy ,
1213} from '@angular/core' ;
1314import { TestBed , ComponentFixture , fakeAsync , flush , tick } from '@angular/core/testing' ;
1415import { DragDropModule } from './drag-drop-module' ;
@@ -533,6 +534,27 @@ describe('CdkDrag', () => {
533534 expect ( dropZone . element . nativeElement . classList ) . not . toContain ( 'cdk-drop-dragging' ) ;
534535 } ) ) ;
535536
537+ it ( 'should toggle a class when the user starts dragging an item with OnPush change detection' ,
538+ fakeAsync ( ( ) => {
539+ const fixture = createComponent ( DraggableInOnPushDropZone ) ;
540+ fixture . detectChanges ( ) ;
541+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
542+ const dropZone = fixture . componentInstance . dropInstance ;
543+
544+ expect ( dropZone . element . nativeElement . classList ) . not . toContain ( 'cdk-drop-list-dragging' ) ;
545+
546+ startDraggingViaMouse ( fixture , item ) ;
547+
548+ expect ( dropZone . element . nativeElement . classList ) . toContain ( 'cdk-drop-list-dragging' ) ;
549+
550+ dispatchMouseEvent ( document , 'mouseup' ) ;
551+ fixture . detectChanges ( ) ;
552+ flush ( ) ;
553+ fixture . detectChanges ( ) ;
554+
555+ expect ( dropZone . element . nativeElement . classList ) . not . toContain ( 'cdk-drop-dragging' ) ;
556+ } ) ) ;
557+
536558 it ( 'should not toggle dragging class if the element was not dragged more than the threshold' ,
537559 fakeAsync ( ( ) => {
538560 const fixture = createComponent ( DraggableInDropZone , [ ] , 5 ) ;
@@ -1807,22 +1829,22 @@ class StandaloneDraggableWithMultipleHandles {
18071829 @ViewChildren ( CdkDragHandle ) handles : QueryList < CdkDragHandle > ;
18081830}
18091831
1810- @ Component ( {
1811- template : `
1812- <div
1813- cdkDropList
1814- style="width: 100px; background: pink; "
1815- [id ]="dropZoneId "
1816- [cdkDropListData]="items"
1817- (cdkDropListDropped)="droppedSpy($event)">
1818- <div
1819- *ngFor="let item of items"
1820- cdkDrag
1821- [cdkDragData]=" item"
1822- style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">{{item}} </div>
1823- </div>
1824- `
1825- } )
1832+ const DROP_ZONE_FIXTURE_TEMPLATE = `
1833+ <div
1834+ cdkDropList
1835+ style="width: 100px; background: pink;"
1836+ [id]="dropZoneId "
1837+ [cdkDropListData ]="items "
1838+ (cdkDropListDropped)="droppedSpy($event)">
1839+ <div
1840+ *ngFor="let item of items"
1841+ cdkDrag
1842+ [cdkDragData]="item"
1843+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">{{ item}}</div>
1844+ </div>
1845+ ` ;
1846+
1847+ @ Component ( { template : DROP_ZONE_FIXTURE_TEMPLATE } )
18261848class DraggableInDropZone {
18271849 @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
18281850 @ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
@@ -1833,6 +1855,12 @@ class DraggableInDropZone {
18331855 } ) ;
18341856}
18351857
1858+ @Component ( {
1859+ template : DROP_ZONE_FIXTURE_TEMPLATE ,
1860+ changeDetection : ChangeDetectionStrategy . OnPush ,
1861+ } )
1862+ class DraggableInOnPushDropZone extends DraggableInDropZone { }
1863+
18361864
18371865@Component ( {
18381866 encapsulation : ViewEncapsulation . None ,
0 commit comments