When using Drag and Drop via Angular Material CDK, it allows you to "snap to grid" via [cdkDragConstrainPosition]="computedDragRenderPos"
Example:
<div cdkDrag [cdkDragConstrainPosition]="computeDragRenderPos">
...
</div>
export class MyDraggableComponent {
constructor() {}
computeDragRenderPos(pos, dragRef) {
return {x: Math.floor(pos.x / 30) * 30, y: pos.y}; // will render the element every 30 pixels horizontally
}
}
However, that passes in pos which is the mouse pos. I understand you can pass dragRef and get the element's getBoundingClientRect to get the x but as soon as you pass that into the cdkDragConstrainPosition position and change the position of the element it no longer works.
How do you move an internal element every 30px.... and not the position of the start of the element?