@@ -1513,6 +1513,26 @@ describe('CdkDrag', () => {
1513
1513
expect ( preview . getAttribute ( 'id' ) ) . toBeFalsy ( ) ;
1514
1514
} ) ) ;
1515
1515
1516
+ it ( 'should clone the content of descendant canvas elements' , fakeAsync ( ( ) => {
1517
+ const fixture = createComponent ( DraggableWithCanvasInDropZone ) ;
1518
+ fixture . detectChanges ( ) ;
1519
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1520
+ const sourceCanvas = item . querySelector ( 'canvas' ) as HTMLCanvasElement ;
1521
+
1522
+ // via https://stackoverflow.com/a/17386803/2204158
1523
+ expect ( sourceCanvas . getContext ( '2d' ) !
1524
+ . getImageData ( 0 , 0 , sourceCanvas . width , sourceCanvas . height )
1525
+ . data . some ( channel => channel !== 0 ) ) . toBe ( true , 'Expected source canvas to have data.' ) ;
1526
+
1527
+ startDraggingViaMouse ( fixture , item ) ;
1528
+
1529
+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
1530
+ const previewCanvas = preview . querySelector ( 'canvas' ) ! ;
1531
+
1532
+ expect ( previewCanvas . toDataURL ( ) ) . toBe ( sourceCanvas . toDataURL ( ) ,
1533
+ 'Expected cloned canvas to have the same content as the source.' ) ;
1534
+ } ) ) ;
1535
+
1516
1536
it ( 'should clear the ids from descendants of the preview' , fakeAsync ( ( ) => {
1517
1537
const fixture = createComponent ( DraggableInDropZone ) ;
1518
1538
fixture . detectChanges ( ) ;
@@ -3821,6 +3841,47 @@ class ConnectedWrappedDropZones {
3821
3841
done = [ 'Four' , 'Five' , 'Six' ] ;
3822
3842
}
3823
3843
3844
+ @Component ( {
3845
+ template : `
3846
+ <div
3847
+ cdkDropList
3848
+ style="width: 100px; background: pink;"
3849
+ [id]="dropZoneId"
3850
+ [cdkDropListData]="items"
3851
+ (cdkDropListSorted)="sortedSpy($event)"
3852
+ (cdkDropListDropped)="droppedSpy($event)">
3853
+ <div
3854
+ *ngFor="let item of items"
3855
+ cdkDrag
3856
+ [cdkDragData]="item"
3857
+ [style.height.px]="item.height"
3858
+ [style.margin-bottom.px]="item.margin"
3859
+ style="width: 100%; background: red;">
3860
+ {{item.value}}
3861
+ <canvas width="100px" height="100px"></canvas>
3862
+ </div>
3863
+ </div>
3864
+ `
3865
+ } )
3866
+ class DraggableWithCanvasInDropZone extends DraggableInDropZone implements AfterViewInit {
3867
+ constructor ( private _elementRef : ElementRef < HTMLElement > ) {
3868
+ super ( ) ;
3869
+ }
3870
+
3871
+ ngAfterViewInit ( ) {
3872
+ const canvases = this . _elementRef . nativeElement . querySelectorAll ( 'canvas' ) ;
3873
+
3874
+ // Add a circle to all the canvases.
3875
+ for ( let i = 0 ; i < canvases . length ; i ++ ) {
3876
+ const canvas = canvases [ i ] ;
3877
+ const context = canvas . getContext ( '2d' ) ! ;
3878
+ context . beginPath ( ) ;
3879
+ context . arc ( 50 , 50 , 40 , 0 , 2 * Math . PI ) ;
3880
+ context . stroke ( ) ;
3881
+ }
3882
+ }
3883
+ }
3884
+
3824
3885
/**
3825
3886
* Component that passes through whatever content is projected into it.
3826
3887
* Used to test having drag elements being projected into a component.
0 commit comments