Add cdk drag-and-drop features
This issue tracks the high-level addition of drag-and-drop features to the cdk.
@Tiedye My mistake. Updated both Stackblitz demos!
I didn't see this one mentioned anywhere: http://kamilkp.github.io/angular-sortable-view/
Few forks down it works ok for our use cases - I had to implement auto scrolling on any number of scroll-able parents though and fix it on mobile on latest chrome (thanks to passive flag). It is also working nicely in IE 11. On the other hand the version we have in the project is cleaned up a bit more and I think I could make it public if it would help anyone.
Sadly it's only available for angularjs and doesn't seem to be maintained. Maybe some ideas / code could still be reused? It is fully declarative after all. That aside, I have to find / make an alternative as well as we are in the process of migrating. Personally I'd would try to rewrite that - as others outlined, there aren't that many good ones out there.
I think it would be a good idea to wait and see what @crisbeto has in store, how far in development / design process he is.
@crisbeto in case there is no progress on this feature, I've refactored angular-sortable-view to typescript and made it work with angular 5 (and angularjs) I could try to push it and see if we can contribute.
I have a little prototype over here. If you want to play with it I suggest doing so not on a smartphone since I didn't put much effort into the styling of the demo app and it is not mobile friendly.
I am planning on releasing an early version of an Angular library next week. Based on https://stackblitz.com/edit/draggable-system-2.
Of course I hope its ideas will be valuable for a CDK package.
@dirkluijk, Looking forward!
Very nice work @dirkluijk
@dirkluijk Anything you can show us? Eager to see some demo of how this is going to work!
Hello all,
Inspired by @dirkluijk and others, I have put together the following library:
https://github.com/cengiz-dev/angular-drag-and-drop
Demo:
https://stackblitz.com/github/cengiz-dev/angular-drag-and-drop
Let me know what you think.
Cheers
My most recent work is visible on
https://stackblitz.com/edit/draggable-part-5 and https://stackblitz.com/edit/draggable-part-6.
It is the code behind this tutorial: https://www.youtube.com/playlist?list=PLJpL6ImpHi2i1ALq7-x7zRADoole7eq8U.
Next challenges:
- Connecting sortable lists
- Provide different "drag helper element" strategies
- Multi-touch support
- Optimization
I was planning on extracting to a library as well
@cengiz-dev will take a look at your code as well. Expect my feedback in a day or two.
@dirkluijk your example6 sucks with relativly big list (even with virtual scrolled) https://stackblitz.com/edit/draggable-part-6-ovo5rl?file=app/app.component.ts
Whoa, easy. It does not suck, but wasn't yet optimised. Please see this example where it performs a lot better: https://stackblitz.com/edit/draggable-part-6-ycchkt?file=app%2Fapp.component.html
The trick is to handle all pointermove logic outside Angular (using ngZone.runOutsideAngular()). This is a known trick which is used inside Angular CDK as well.
To give an update on the rest of the drag/drop ideas: I am currently struggling with connected sortable lists. The idea is that you can move elements between multiple lists on the fly, e.g. with a single drag operation.
Of course, I can just destroy the old element (view) and create a new one using Angulars ngFor directive. However, in combination with dragging, this is quite hard. On Safari this won't work with the pointer events polyfill because the browser stops emitting pointer events when the original element is destroyed. Also, it would be nice if the original draggable directive remembers its state when moved to another location accross the DOM.
So...
I am looking for a clean way to render multiple lists with a single ng-template and to move views accross multiple view containers. This can be quite hard, because you would have to reuse IterableDiffer logic which is used by Angulars ngForOf and combine it with multiple iterables.
For example: when change detection occurs, and iterable 1 has an item deleted and interable 2 has an item added, this means that the original view should be reused and a ViewContainer.detach() should be performed together with a ViewContainer.insert().
@istiti criticism should always be constructive, not vague, negative and lazy.
@dirkluijk identified a need many in this community have and has shared his solution as well as offered instruction on how build your own implementation, a rare gift and sign of the strength of this community. Legitimate issues with his solution should include specifics ( at what size does it start to suck? ), and hopefully some proposed solution.
Adolescent insults towards contributions is destructive to our community and will not be tolerated.
Nice progress @crisbeto . Checked the demo and found a minor glitch. If the handle is released without moving the element (like a double click for example) sometimes the preview element freezes and the item cant be dragged anymore. Trying to find out why.
Is there a plan to support sorting nested lists both with vertical and horizontal layout? Tried to create a horizontal list of items using float and tried it with flex layout, but sorting is not working properly. I would like to create a kind of configurable dashboard something like this:
@tibortotok https://github.com/angular/material2/pull/12104 got in a couple of hours ago which adds support for horizontal sorting.
Thanks @crisbeto, that sounds great! :)
My newest ideas: https://stackblitz.com/edit/draggable-release-candidate
I finally managed to get the connected sortable list working. Still have issues on Safari. What I like of this approach is that the helper is an actual ng-template so that you can customize its appearance and content.
- multi-touch support (tested on Android)
- animations
- optional drag handle support
@dirkluijk Thanks for the good work! Just for feedback, I noticed the connected sortable list sometimes duplicates a block when dragging from one list to the other. Tested on mobile Android 8.1.0 (so touch) with Chrome 67.0.3396.87.