question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drag&Drop Drop List Dynamic Preview

See original GitHub issue

What are you trying to do?

I want to be able to change the drag and drop preview depending on which container you’re dropping into.

In my stackblitz I have three different containers. The first and third one have regular drag and drop previews, but the second one I’d like to customize the drag and drop preview. Using <img *cdkDragPreview src="https://upload.wikimedia.org/wikipedia/en/4/40/Star_Wars_Phantom_Menace_poster.jpg"> works when dragging elements from the second container, but I’d like the preview to be dynamic depending on where you’re dropping it.

For example, if you grab an item from the first container and drag it over the second, I’d like the preview to be the image. But it you drag that same item over the third, it should switch back to the regular preview.

What troubleshooting steps have you tried?

I’ve tried to manually do it using cdkDragDropEntered and cdkDragDropExited events but it did not work as expected. Especially with the differences in the width of the previews.

Reproduction

https://stackblitz.com/edit/angular-suzb2h

Environment

  • Angular: latest
  • CDK/Material: latest
  • Browser(s): All
  • Operating System (e.g. Windows, macOS, Ubuntu): All

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
angular-robot[bot]commented, Feb 21, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular’s feature request process in our documentation.

1reaction
Achilles1515commented, Jul 21, 2020

@Jonatino Like crisbeto said, this can be done with template input variables and custom event methods.

Example: https://stackblitz.com/edit/angular-suzb2h-vacqfr?file=app%2Fcdk-drag-drop-connected-sorting-group-example.html

Though it is not very pretty, and it is using private DragRef variables to access the preview view ref context.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically look for connected drop lists with Angular CDK ...
I have an HTML element with a mouseenter listener that shows a hidden cdk drop list on mouseenter (with *ngIf). When on drag...
Read more >
Drag and Drop | Angular Material
When a cdkDrag element is picked up, it will create a preview element visible while dragging. By default, this will be a clone...
Read more >
Drag&amp;Drop custom preview - StackBlitz
Drag&Drop custom preview. ... cdk-drag-drop-custom-preview-example.html. Format Document. Split Editor ... <div cdkDropList class="example-list".
Read more >
Using the HTML5 Drag and Drop API - web.dev
The source element can be an image, list, link, file object, block of HTML, etc. The target is the drop zone (or set...
Read more >
How to implement drag and drop in React with React DnD
Display an image preview; Reorder images with drag and drop; React drag and ... is a higher-level abstraction specifically built for lists.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found