components icon indicating copy to clipboard operation
components copied to clipboard

Keep a visual indication of where the cdkDrag element is when starting to drag

Open Diemauerdk opened this issue 6 years ago • 18 comments
trafficstars

Please describe the feature you would like to request.

Whenever the user starts to drag an element it must be possible to have a visual indication of where in the list the element is being dragged from until it is dropped.

What is the use-case or motivation for this proposal?

While dragging an element it is in many scenarios very important that you know where the element was originally placed because that information is currently lost when starting to drag.

This is important in all scenarios where the order of draggable elements is critical. If the order of the elements are critical and you start to drag an element and then lose the original position, then the user is forced to remember the position of the element or drop the element somewhere.

Is there anything else we should know?

Diemauerdk avatar Jan 31 '19 12:01 Diemauerdk

This is possible already, you just have to style the .cdk-drag-placeholder. Here's an example.

crisbeto avatar Jan 31 '19 12:01 crisbeto

Thanks for answering that fast.

Then I think you have misunderstood my question. At least I don't see the functionality in the example :)

In the example, you link to: When I start to drag an element then there is no placeholder of where it was placed. I can only see the placeholder of where it is going to be placed.

What I am looking for is a visual indication of where the element was placed and not going to be placed :)

Diemauerdk avatar Jan 31 '19 13:01 Diemauerdk

Ah, I see. Reopening.

crisbeto avatar Jan 31 '19 13:01 crisbeto

This would be a very useful feature. In fact, if we look at Google Drive UI, this is what happened there. When you click a file, then start dragging it, there is a placeholder where the file was (but with <1 opacity), and there is another shrunk box "holding" this file.

I am currently trying to implement this functionality but it seems that currently with cdk-drag-drop this is still not easy?

zhaodong-wang avatar Feb 17 '19 04:02 zhaodong-wang

@TeXnicians I have been trying to implement it too. My approach was making a copy of the item being dragged and inserting it at the index of the original item. I gave the copy a reduced opacity and when the dragged item was dropped I removed the copy element from the list. This simulated it but with a few problems.

The main problem was that the copied element behaved as it was not a part of the list when dragging. After "hacking" the CDK framework a lot, the conclusion I ended up with was that this needs to be handled within the angular CDK drag and drop in order to get the best experience.

I can see a lot of business scenarios where this feature is an essential requirement.

Diemauerdk avatar Feb 21 '19 09:02 Diemauerdk

@Diemauerdk I was trying to implement it in the other way around: I finally gave up using cdk framework but using the drag&drop of HTML5: listening to the events dragstart, drag, dragend, etc and add draggable to the element. So I can customize those animations (by creating DOM elements). I can pretty much reproduce the effects in Google Drive now.

zhaodong-wang avatar Feb 24 '19 19:02 zhaodong-wang

I was looking for the same feature in the current CDK, just realized its not. Any plans to get this implemented ?

Pradins avatar Mar 27 '19 11:03 Pradins

Can't you achieve what you want by putting transform: translate(0px, 0px) !important; on the class .cdk-drag?

Pedrozxcv avatar Aug 06 '19 14:08 Pedrozxcv

+1

shyamal890 avatar Oct 08 '19 09:10 shyamal890

+1

ShakinFire avatar Oct 17 '19 11:10 ShakinFire

+1

sdrozdz avatar Feb 05 '20 08:02 sdrozdz

I think this feature is essential as it could be useful for some business scenarios and solve some problems due to dimension changes when a user drag an item from one list to another that is below. If the origin list keeps a copy of the item, it's height won't change when the user drags the item over the underneath list. So the underneath list position won't change either preventing a sudden move of the list relatively to the mouse position which can lead to a buggy sensation.

drag-n-drop-position-change

As you can see in the gif above, the dragged element placeholder is not placed above the "6" when the dragged element enters in it because the second list move to the top.

When the dragged element is moved slower it leads to another weird behavior as you can see in the next gif.

drag-n-drop-position-change2

Gifs based on : https://stackblitz.com/edit/angular-mbwtxv

fredpeaks avatar Feb 09 '20 14:02 fredpeaks

+1

kamil-zielinski avatar Aug 11 '20 12:08 kamil-zielinski

+1

rxseb avatar Dec 30 '20 23:12 rxseb

+1

angelinabylitskaya avatar Jan 08 '21 11:01 angelinabylitskaya

Is there an approximate estimation of when it's going to be implemented? Because this is kind of essential feature of DnD. If anyone is interested, the workaround that looks at least ok to me (as I can't think of some better CSS solution) would be to apply box-shadow on .cdk-drag-placeholder. With lowered opacity. Also, transform should be disabled (otherwise placeholder will move). Something like this:

.cdk-drag-placeholder {
    box-shadow: 0 0 3px 3px *color*;
    opacity   : 0.6;
    transform : none !important;
}

Approximate result (dragging "Item 3" here):

image

liesahead avatar Apr 01 '21 10:04 liesahead

+1

fmancuso avatar Apr 11 '24 11:04 fmancuso

+1

amaylunagaria avatar Sep 24 '24 12:09 amaylunagaria

+1, never lose hope

vvolodin avatar Nov 13 '24 22:11 vvolodin

+1

Siminho9 avatar Jun 16 '25 14:06 Siminho9

This should be resolved by https://github.com/angular/components/pull/31288.

crisbeto avatar Jun 18 '25 07:06 crisbeto

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.