Drag&Drop Drop List Dynamic Preview
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top GitHub Comments
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.
@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.