-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Add cdk drag-and-drop features #8963
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
Comments
Is there any design doc I can follow @jelbourn ? I've tried quite a few drag and drop libraries, all of the are bad in one way or another, those that use native APIs are rather limited when it comes to styling the content (which is also often glitched when you drag an item that is partially hidden behind overflow) that is being dragged and those that do it programatically often don't have must have accessibility features like scrolling when the item being dragged is on the side of the scrollable element, so I really wonder how you gonna tackle this. |
Kristiyan is working on a design now. Any specific feedback you have about what you like/dislike about other libraries would be good to know. |
Most of the libs (with native html dnd) such as angular-dnd, sortablejs, dragula handle DOM on their own which is very inconvinient when using unidirectional dataflow (ngrx). There is no an easy way to cancel these updates and walkarounds feel very hacky. This is the biggest issue with all the libs I've used so far
Would be awesome if we would get something like https://github.com/atlassian/react-beautiful-dnd |
Additionally, most seem designed to simply append elements onto lists of other elements when dropped into a drop zone. I would love to see a "canvas" mode implemented to simplify the dropping into an absolute position of an element. This would be extremely useful for design oriented apps, where the user is building something from smaller elements. I used interactjs years ago and really appreciated all it's features ( touch support, inertia, grid snapping, svg support ). It's an older library but could prove useful at least for feature ideas. I'm ready to contribute in any way I can once you all have laid the plans and groundwork. |
As mentioned dojchek full support for state management like ngrx/redux is very important. We don't yet have an angular dnd library that does. |
What would be an example of a scenario w/ ngrx interplay with drag-and-drop? |
Not sure if this is quite the example you're looking for but I have a site that I maintain that uses drag and drop to create a data sorting functionality. We built it to be closely tied into ngrx where each of the containers (items to be sorted and a container for each category is populated via ngrx store selector. When the user drags an item from one list to another, we cancel all the default drag/drop actions and instead fire a ngrx event that updates the object in question with the new category and let the container selectors "move" the item (this allows for some other things like firing save events and such). Having something built into the cdk that could facility the drag/drop actions and allow me to intercept at certain events (ie. onDrop) to do things like fire ngrx action and cancel any further drag/drop effects would be great. |
I've ported an angularjs library but intentionally just implemented drop zones to be as general purpose as possible. By having a general purpose drop zone all the ngrx use cases should be possible as well because the library just informs you something has been dropped. What should happen with that event is all up to the developer. https://github.com/reppners/ngx-drag-drop So if you're asking for features I'd like to see for CDK than all of what the mentioned library does because it's quite basic (does not do the lists or sorting stuff internally) but configurable to cater all use cases. Wether it's implemented with native HTML5 drag-and-drop or implementing it all in the angular stack is up to you, but what I'd like to be possible is drag stuff from the outside of the browser into an app. This is just possible with native drag-and-drop. |
It's probably important to come up with a list of drag, and drag and drop related use cases. What sort of things are we dragging? What sort of drop targets are we going to have? I suspect there's probably more permutations of the latter: single drop targets, groups of drop targets, nested drop targets. There's also a variety of ways that you might want to execute logic when interacting with those targets while dragging or dropping. ngrx FWIW, I wouldn't worry about Redux or ngrx when it came to current drag state. That's really a UI concern, and not something I would do as critical to persist to state. |
Interesting library written in ES6 Drag and Drop lib |
If we could have this: https://github.com/react-dnd/react-dnd for angular, I would be very satisfied. |
I am working on drag and drop in an Angular app this week. @dojchek already mentioned most of the features required for my use case, but here are a couple more:
|
Would be great! On our teams wish list:
Another trick/feature is to have the center of the ghost element as reference for the drop behaviour (instead of the pointers position). E.g. you start dragging an element by "grabbing" it at its left side, and when the center of the dragged element covers the dropzone, but your pointer is not hovering it, you still want to be able to drop it in the dropzone? By the way. When sharing ideas, why not sharing Stackblitzes? |
Today I found some time to work out some ideas. Please see: https://stackblitz.com/edit/draggable-system What is in it:
The directives:
Just wanted to drop my ideas here... |
@dirkluijk It it supposed to be interactive? I had a look and nothing was draggable, is it supposed to be? |
Oops, forgot to add polyfill for pointer events. I guess you checked on a mobile browser. Should work now! |
Nah just Firefox, seems they don't have it enabled by default yet.
On Feb 16, 2018 6:02 PM, Dirk Luijk <[email protected]> wrote:
Oops, forgot to add polyfill for pointer events. I guess you checked on a mobile browser. Should work now!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#8963 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AF5opZI0f_njRwOL1dNdty2Guf1qVYD5ks5tVgkbgaJpZM4Q_jF0>.
|
Firefox worked for me. |
Here is a second version with some droppable ideas demonstrated: https://stackblitz.com/edit/draggable-system-2
|
@dirkluijk looks like the polyfill you added didn't stick, it works great when I do add the polyfill though! |
@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. |
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. |
Just added this to my app, and it's working great with my nested dnd lists! I noticed that there there is a bug where draggables don't animate correctly during the drag phase, if list items have variable heights. Is it useful to create a bug ticket for this while still under active development? Regardless—nice work, so far! |
@BirdInTheCity yes, it would be useful to have a ticket for it. |
@crisbeto Posted the bug. Includes animated gif to help explain. Take a look. Thanks! |
Was trying to use cdkDrag earlier and getting griefed a fair bit. After making a minimal reproduction in StackBlitz I realised that the Reproduction: https://stackblitz.com/edit/angular-3h4hbb?file=src%2Fapp%2Fapp.component.html |
To @Tiedye and others — as @thefliik noted above, I built the react-dnd implementation, I see that Cdk is targeting a sortable, and angular-skyhook is much more general purpose than that, but I am working on a sortable implementation on top — if anyone has any input on the API design or wants to contribute, it would be very welcome over at cormacrelf/angular-skyhook#69. (Also, @crisbeto, I read the comments about change detection on fast-moving values — you may find some of the core angular-skyhook code interesting. I used a separate zone for all code, that comes back to Angular when users opt into events they’re interested in (‘interested’ = distinctUntilChanged on the listen() observable, or a spec method is provided). Observables can even be scheduled to have CD run after they are processed. It works optimally, even as a blanket rule.) |
This is something that came up during a discussion in #8963. Adds the `cdkDragMoved` event which will emit as an item is being dragged. Also adds some extra precautions to make sure that we're not doing extra work unless the consumer opted into the event.
A nice place to get started I found this on google. https://github.com/misha130/ngx-drag-and-drop-lists |
Really the drag and drop feature addition. However I noticed a problem where input elements such as buttons, text fields, and checkboxes don't receive click events. All clicks on a CdkDrag element seem to be fire a CdkDragDrop event but no click event. Is the CdkDragDrop event consuming the click and preventing the click from passing through to the input element? Has anyone been able to get a button working in a CdkDrag element? Here's a stackblitz with the minimum code necessary to reproduce the issue: https://angular-qpqmw8.stackblitz.io Let me know if it'd help to create an issue for this. |
@ptoro seems like you would want a drag handle on any of those elements if you'd like to drag them. I can see how it would be useful for a form builder or something similar but you'd remove the |
Not necessarily. For example, think of an image gallery where you might want to be able to drag a picture to reorder it but also click to enlarge it. It's not just an image gallery though. It's true any time you have an element itself you want to grab hold of to drag but also click. Even regardless of individual use cases, a drag and drop library should not consume all ClickEvents as all ClickEvents are not drag and drop events and should be available for consumption by the developer. Dragula (ng2-dragula) does a good job implementing this: https://valor-software.com/ng2-dragula/index.html (scroll to the section "Click or Drag!"). |
Thanks for creating that PR @crisbeto. Playing around with the feature a bit more, I ran into another problem. If you want to only allow one-way dragging (e.g. left list to right list), you remove the I can provide a StackBiltz but the only change I had to make from this StackBlitz for the Transferring items between lists example to reproduce this behavior was to remove Happy to create an issue for this if necessary. |
Thanks for the report @ptoro, could you file your exact comment as an issue? I'm closing down this issue since the drag&drop is close to being released in stable and having issues in here makes them hard to track over time. |
Can't resolve '@angular/cdk/drag-drop' https://beta-angular-material-io.firebaseapp.com/cdk/drag-drop/api#directives unable to resolve the dependency . Any help ? @crisbeto |
Try |
@nayfin Didn't seem folder is here. |
Sorry, you also need |
@nayfin Is something wrong here ?
|
I doubt there is a schematic for it. Just add to dependencies and |
@nayfin Did npm install up to date in 30.943s |
Those are just warnings telling you that you're using Windows |
@nayfin Any idea why such behaviour |
Would you mind to move your support questions over to StackOverflow or Gitter? Everyone who follows this issue gets notified. The Angular team kindly asks to keep issues clean for bugs etc.
Thanks <3 |
@pas2al My bad, Regards. |
@nallwhy Just for update Is working as expected. |
Locking this thread since it's gone off-topic now. Drag-and-drop is being released as part of Angular v7. Feel free to open new issues for bug reports. |
This issue tracks the high-level addition of drag-and-drop features to the cdk.
The text was updated successfully, but these errors were encountered: