'Angular cdk drap drop - dynamic placeholder height
I want to set the placeholder height to height of dragging element.
For now I'm using static height placeholder of smallest possible element height. I couldn't find any informations about how to do it and for now having no idea.
component html
<div class="taskList" cdkDropList id="{{ 'cdk-task-drop-list-' + categoryId }}" [cdkDropListData]="taskList"
[cdkDropListConnectedTo]="categoryIdList" (cdkDropListDropped)="onDrop($event)">
<ng-container *ngIf="task.isApproved || task.authorId===userId || userAccessLevel >= 3">
<div class="placeholder" *cdkDragPlaceholder></div>
<div class="task">
...
</div>
</ng-container>
</div>
css
.placeholder{
position: relative;
margin-top: 1px;
margin-bottom: 5px;
min-height: 75px;
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
vertical-align: middle;
}
Any ideas?
Solution 1:[1]
Try to get height of dragging element, and based on this, change placeholder height.
cdkDragStarted(event:any){
this.height = event.source.element.nativeElement.offsetHeight
}
HTML:
<div class="example-box" *ngFor="let movie of movies; let i = index" (cdkDragStarted)="cdkDragStarted($event)" cdkDrag >
<div [ngStyle]="{'min-height.px':height }" class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{movie}}
</div>
Here is my example: https://stackblitz.com/edit/angular-zhdujp-kppghs?file=src/app/cdk-drag-drop-custom-placeholder-example.ts
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BartoszTermena |
