Skip to content

fix(drag-drop): only add top-level drop lists to drop group #14130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/cdk/drag-drop/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {CdkDragDrop} from './drag-events';
import {moveItemInArray} from './drag-utils';
import {CdkDropList} from './drop-list';
import {CdkDragHandle} from './drag-handle';
import {CdkDropListGroup} from './drop-list-group';

const ITEM_HEIGHT = 25;
const ITEM_WIDTH = 75;
Expand Down Expand Up @@ -2121,6 +2122,14 @@ describe('CdkDrag', () => {
expect(fixture.componentInstance.droppedSpy).not.toHaveBeenCalled();
}));

it('should not add child drop lists to the same group as their parents', fakeAsync(() => {
const fixture = createComponent(NestedDropListGroups);
const component = fixture.componentInstance;
fixture.detectChanges();

expect(Array.from(component.group._items)).toEqual([component.listOne, component.listTwo]);
}));

});

});
Expand Down Expand Up @@ -2491,6 +2500,25 @@ class ConnectedDropZonesWithSingleItems {
droppedSpy = jasmine.createSpy('dropped spy');
}

@Component({
template: `
<div cdkDropListGroup #group="cdkDropListGroup">
<div cdkDropList #listOne="cdkDropList">
<div cdkDropList #listThree="cdkDropList"></div>
<div cdkDropList #listFour="cdkDropList"></div>
</div>

<div cdkDropList #listTwo="cdkDropList"></div>
</div>
`
})
class NestedDropListGroups {
@ViewChild('group') group: CdkDropListGroup<CdkDropList>;
@ViewChild('listOne') listOne: CdkDropList;
@ViewChild('listTwo') listTwo: CdkDropList;
}


/**
* Component that passes through whatever content is projected into it.
* Used to test having drag elements being projected into a component.
Expand Down
3 changes: 2 additions & 1 deletion src/cdk/drag-drop/drop-list-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {Directive, OnDestroy} from '@angular/core';
* from `cdkDropList`.
*/
@Directive({
selector: '[cdkDropListGroup]'
selector: '[cdkDropListGroup]',
exportAs: 'cdkDropListGroup',
})
export class CdkDropListGroup<T> implements OnDestroy {
/** Drop lists registered inside the group. */
Expand Down
5 changes: 4 additions & 1 deletion src/cdk/drag-drop/drop-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Optional,
Directive,
ChangeDetectorRef,
SkipSelf,
} from '@angular/core';
import {Directionality} from '@angular/cdk/bidi';
import {CdkDrag} from './drag';
Expand Down Expand Up @@ -81,6 +82,8 @@ interface ListPositionCacheEntry {
selector: '[cdkDropList], cdk-drop-list',
exportAs: 'cdkDropList',
providers: [
// Prevent child drop lists from picking up the same group as their parent.
{provide: CdkDropListGroup, useValue: undefined},
{provide: CDK_DROP_LIST_CONTAINER, useExisting: CdkDropList},
],
host: {
Expand Down Expand Up @@ -149,7 +152,7 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
private _dragDropRegistry: DragDropRegistry<CdkDrag, CdkDropList<T>>,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() private _dir?: Directionality,
@Optional() private _group?: CdkDropListGroup<CdkDropList>) {}
@Optional() @SkipSelf() private _group?: CdkDropListGroup<CdkDropList>) {}

ngOnInit() {
this._dragDropRegistry.registerDropContainer(this);
Expand Down