Skip to content

feat(drag-drop): add directive to connect drop lists automatically #13754

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 10, 2018

Conversation

crisbeto
Copy link
Member

Currently the only way to connect drop lists is via the cdkDropListConnectedTo input which works if the consumer knows the amount of drop lists that they're going to have. For dynamic lists they can pass a list of ids, however that can be a little boilerplate-y. These changes introduce the cdkDropListGroup directive which can be used to connect a dynamic list of drop containers automatically.

Fixes #13750.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Oct 22, 2018

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

if (this._group) {
this._group._items.add(this);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating whether this should live in the CdkDropRegistry. I decided not to do it, because it was adding a fair bit of code for no real benefit.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 22, 2018
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -39,6 +39,19 @@ referencing the `id` of another drop container:
<div cdkDropList id="list-two" [cdkDropListConnectedTo]="['list-one']"></div>
```

If you have an unknown amount of connected drop lists, you can use the `cdkDropListGroup` directive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"amount" -> "number"

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Oct 24, 2018
@crisbeto crisbeto force-pushed the 13750/drop-list-group branch from 4515121 to 554c727 Compare October 25, 2018 17:44
@ngbot
Copy link

ngbot bot commented Nov 3, 2018

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@lightheaded
Copy link

This is fantastic and immensely useful! Much appreciated, @crisbeto

@sroettering
Copy link

Doesn't this approach for grouping drop lists require the lists to be in the same template?
How would you handle an arbitrary and dynamic number of drop lists that are scattered around the application?
I'm thinking of a use case where you have a list of items in a sidebar that can be dragged around and dropped in different lists or tables on the page. So there would be a need for a drop list group that can cross component boundaries.

Before seeing this PR I was thinking about an API for a drop list group mechanism like this:

<div cdkDropList [cdkDropListGroup]="<some-group-id>">
    <!-- Some draggable items in here -->
</div>

@philmtd
Copy link

philmtd commented Nov 7, 2018

Having cdkDropLists connected with an identifier or something similar would be gold!

@crisbeto crisbeto force-pushed the 13750/drop-list-group branch from 10d06f7 to 3715fa6 Compare November 8, 2018 08:11
Currently the only way to connect drop lists is via the `cdkDropListConnectedTo` input which works if the consumer knows the amount of drop lists that they're going to have. For dynamic lists they can pass a list of ids, however that can be a little boilerplate-y. These changes introduce the `cdkDropListGroup` directive which can be used to connect a dynamic list of drop containers automatically.

Fixes angular#13750.
@crisbeto
Copy link
Member Author

crisbeto commented Nov 8, 2018

@sroettering at that point it would be better to generate some kind of identifier for each item and then connect them through cdkDropListConnectedTo. This directive is intended the to handle the most common use case where you have an unknown amount of connected lists within the same component.

@philmtd You can already connect lists by their string id.

@philmtd
Copy link

philmtd commented Nov 8, 2018

Yes but then I'd need to know how many lists there are and which IDs they have. When I have lists generated by an *ngFor and additionally other lists that are static it would probably be easier to connect them by a group id.

@lightheaded
Copy link

lightheaded commented Nov 8, 2018

@philmtd while I agree with the idea, you are describing a different use case more appropriate for a separate pull request extending the functionality of cdkDropListConnectedTo to allow connecting lists via classes or something similar

@sroettering
Copy link

@lightheaded sure this would be another pull request, but that functionality would make this pull request obsolete. So maybe it should be discussed a little more.

@vivian-hu-zz vivian-hu-zz merged commit 962dbeb into angular:master Nov 10, 2018
@sebamed
Copy link

sebamed commented Nov 11, 2018

Hey guys, glad I found this feature. But, I'm having some troubles implementing it, can't really get it to work. Could anyone take a look at this question on stackoverflow?

EDIT

After some struggle, I managed to find a workaround with list ids array. Check my answer here.

@crisbeto
Copy link
Member Author

These changes haven't been released yet.

vivian-hu-zz pushed a commit that referenced this pull request Nov 12, 2018
…13754)

Currently the only way to connect drop lists is via the `cdkDropListConnectedTo` input which works if the consumer knows the amount of drop lists that they're going to have. For dynamic lists they can pass a list of ids, however that can be a little boilerplate-y. These changes introduce the `cdkDropListGroup` directive which can be used to connect a dynamic list of drop containers automatically.

Fixes #13750.
@FritzHerbers
Copy link

Besides having a grouped functionality I needed a list who can act as a template. Drags can be transfered/copied from the template to any list.

I wrapped the cdkDropList in a component, which registers/unregisters itself to a dragging service, specifiying the group and if it is a template. [cdkDropListConnectedTo] queries with group and isTemplate the dragging service.

Having a register/unregister callback would be nice, and also keeps the strategy wanted part of the application.

crisbeto added a commit to crisbeto/material2 that referenced this pull request Dec 17, 2018
Adds an example that was being embedded in the readme, but isn't in the docs. It seems like it was missed in angular#13754 where a reference to it was introduced.
jelbourn pushed a commit that referenced this pull request Dec 18, 2018
Adds an example that was being embedded in the readme, but isn't in the docs. It seems like it was missed in #13754 where a reference to it was introduced.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
Adds an example that was being embedded in the readme, but isn't in the docs. It seems like it was missed in angular#13754 where a reference to it was introduced.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drag and Drop - Lists connected to all lists.
9 participants