@@ -24,6 +24,7 @@ import {
2424import { TestBed , ComponentFixture , fakeAsync , flush , tick } from '@angular/core/testing' ;
2525import { DOCUMENT } from '@angular/common' ;
2626import { ViewportRuler } from '@angular/cdk/scrolling' ;
27+ import { _supportsShadowDom } from '@angular/cdk/platform' ;
2728import { of as observableOf } from 'rxjs' ;
2829
2930import { DragDropModule } from '../drag-drop-module' ;
@@ -4010,6 +4011,39 @@ describe('CdkDrag', () => {
40104011 cleanup ( ) ;
40114012 } ) ) ;
40124013
4014+ it ( 'should be able to drop into a new container inside the Shadow DOM' , fakeAsync ( ( ) => {
4015+ // This test is only relevant for Shadow DOM-supporting browsers.
4016+ if ( ! _supportsShadowDom ( ) ) {
4017+ return ;
4018+ }
4019+
4020+ const fixture = createComponent ( ConnectedDropZonesInsideShadowRoot ) ;
4021+ fixture . detectChanges ( ) ;
4022+
4023+ const groups = fixture . componentInstance . groupedDragItems ;
4024+ const item = groups [ 0 ] [ 1 ] ;
4025+ const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
4026+
4027+ dragElementViaMouse ( fixture , item . element . nativeElement ,
4028+ targetRect . left + 1 , targetRect . top + 1 ) ;
4029+ flush ( ) ;
4030+ fixture . detectChanges ( ) ;
4031+
4032+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
4033+
4034+ const event = fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
4035+
4036+ expect ( event ) . toEqual ( {
4037+ previousIndex : 1 ,
4038+ currentIndex : 3 ,
4039+ item,
4040+ container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
4041+ previousContainer : fixture . componentInstance . dropInstances . first ,
4042+ isPointerOverContainer : true ,
4043+ distance : { x : jasmine . any ( Number ) , y : jasmine . any ( Number ) }
4044+ } ) ;
4045+ } ) ) ;
4046+
40134047 } ) ;
40144048
40154049 describe ( 'with nested drags' , ( ) => {
@@ -4389,65 +4423,68 @@ class DraggableInDropZoneWithCustomPlaceholder {
43894423 renderPlaceholder = true ;
43904424}
43914425
4426+ const CONNECTED_DROP_ZONES_STYLES = [ `
4427+ .cdk-drop-list {
4428+ display: block;
4429+ width: 100px;
4430+ min-height: ${ ITEM_HEIGHT } px;
4431+ background: hotpink;
4432+ }
43924433
4393- @Component ( {
4394- encapsulation : ViewEncapsulation . None ,
4395- styles : [ `
4396- .cdk-drop-list {
4397- display: block;
4398- width: 100px;
4399- min-height: ${ ITEM_HEIGHT } px;
4400- background: hotpink;
4401- }
4434+ .cdk-drag {
4435+ display: block;
4436+ height: ${ ITEM_HEIGHT } px;
4437+ background: red;
4438+ }
4439+ ` ] ;
44024440
4403- .cdk-drag {
4404- display: block;
4405- height: ${ ITEM_HEIGHT } px;
4406- background: red;
4407- }
4408- ` ] ,
4409- template : `
4441+ const CONNECTED_DROP_ZONES_TEMPLATE = `
4442+ <div
4443+ cdkDropList
4444+ #todoZone="cdkDropList"
4445+ [cdkDropListData]="todo"
4446+ [cdkDropListConnectedTo]="[doneZone]"
4447+ (cdkDropListDropped)="droppedSpy($event)"
4448+ (cdkDropListEntered)="enteredSpy($event)">
44104449 <div
4411- cdkDropList
4412- #todoZone="cdkDropList"
4413- [cdkDropListData]="todo"
4414- [cdkDropListConnectedTo]="[doneZone]"
4415- (cdkDropListDropped)="droppedSpy($event)"
4416- (cdkDropListEntered)="enteredSpy($event)">
4417- <div
4418- [cdkDragData]="item"
4419- (cdkDragEntered)="itemEnteredSpy($event)"
4420- *ngFor="let item of todo"
4421- cdkDrag>{{item}}</div>
4422- </div>
4450+ [cdkDragData]="item"
4451+ (cdkDragEntered)="itemEnteredSpy($event)"
4452+ *ngFor="let item of todo"
4453+ cdkDrag>{{item}}</div>
4454+ </div>
44234455
4456+ <div
4457+ cdkDropList
4458+ #doneZone="cdkDropList"
4459+ [cdkDropListData]="done"
4460+ [cdkDropListConnectedTo]="[todoZone]"
4461+ (cdkDropListDropped)="droppedSpy($event)"
4462+ (cdkDropListEntered)="enteredSpy($event)">
44244463 <div
4425- cdkDropList
4426- #doneZone="cdkDropList"
4427- [cdkDropListData]="done"
4428- [cdkDropListConnectedTo]="[todoZone]"
4429- (cdkDropListDropped)="droppedSpy($event)"
4430- (cdkDropListEntered)="enteredSpy($event)">
4431- <div
4432- [cdkDragData]="item"
4433- (cdkDragEntered)="itemEnteredSpy($event)"
4434- *ngFor="let item of done"
4435- cdkDrag>{{item}}</div>
4436- </div>
4464+ [cdkDragData]="item"
4465+ (cdkDragEntered)="itemEnteredSpy($event)"
4466+ *ngFor="let item of done"
4467+ cdkDrag>{{item}}</div>
4468+ </div>
44374469
4470+ <div
4471+ cdkDropList
4472+ #extraZone="cdkDropList"
4473+ [cdkDropListData]="extra"
4474+ (cdkDropListDropped)="droppedSpy($event)"
4475+ (cdkDropListEntered)="enteredSpy($event)">
44384476 <div
4439- cdkDropList
4440- #extraZone="cdkDropList"
4441- [cdkDropListData]="extra"
4442- (cdkDropListDropped)="droppedSpy($event)"
4443- (cdkDropListEntered)="enteredSpy($event)">
4444- <div
4445- [cdkDragData]="item"
4446- (cdkDragEntered)="itemEnteredSpy($event)"
4447- *ngFor="let item of extra"
4448- cdkDrag>{{item}}</div>
4449- </div>
4450- `
4477+ [cdkDragData]="item"
4478+ (cdkDragEntered)="itemEnteredSpy($event)"
4479+ *ngFor="let item of extra"
4480+ cdkDrag>{{item}}</div>
4481+ </div>
4482+ ` ;
4483+
4484+ @Component ( {
4485+ encapsulation : ViewEncapsulation . None ,
4486+ styles : CONNECTED_DROP_ZONES_STYLES ,
4487+ template : CONNECTED_DROP_ZONES_TEMPLATE
44514488} )
44524489class ConnectedDropZones implements AfterViewInit {
44534490 @ViewChildren ( CdkDrag ) rawDragItems : QueryList < CdkDrag > ;
@@ -4472,6 +4509,15 @@ class ConnectedDropZones implements AfterViewInit {
44724509 }
44734510}
44744511
4512+ @Component ( {
4513+ encapsulation : ViewEncapsulation . ShadowDom ,
4514+ styles : CONNECTED_DROP_ZONES_STYLES ,
4515+ template : CONNECTED_DROP_ZONES_TEMPLATE
4516+ } )
4517+ class ConnectedDropZonesInsideShadowRoot extends ConnectedDropZones {
4518+ }
4519+
4520+
44754521@Component ( {
44764522 encapsulation : ViewEncapsulation . None ,
44774523 styles : [ `
0 commit comments