Positioning Custom Drag and Drop Hints
Environment
Product | Progress® Kendo UI Drag and Drop |
Description
How can I change the default position of the custom drag hint of the Kendo UI for Angular Drag and Drop utility?
Solution
When utilizing a custom hint element that is smaller than the drag target, it may appear offset from the mouse pointer, requiring manual position adjustments. To customize the default hint position:
-
Handle the
onDrag
event of the element with thekendoDragTarget
directive applied.<!-- Considering the drag element is bigger that the hint. --> <div kendoDragTarget (onDrag)="onDrag($event)" [hint]="{hintTemplate: hint}"> Drag Me! </div> <!-- Considering the hint element has smaller dimensions. --> <ng-template #hint > <div> DRAG HINT <div> </ng-template>
-
Prevent the default
onDrag
event behavior and use theRenderer2
to set thetop
andleft
CSS properties of the hint element to theclientX
andclientY
values.constructor(private r: Renderer2) {} public onDrag(e: DragTargetDragEvent): void { e.preventDefault(); this.topValue = `${e.dragEvent.clientY}px`; this.leftValue = `${e.dragEvent.clientX}px`; this.r.setStyle(e.hintElement, 'top', this.topValue); this.r.setStyle(e.hintElement, 'left', this.leftValue); }