0

I'm facing some strange CdkDrag behavior, when draggable element is wider than container, even dragging for like few pixels, instantly drags to end of draggable element.

CdkDrag Behavior

Any idea how to make it drag smoothly, as it works with red square?

lambidu
  • 1,038
  • 10
  • 19

1 Answers1

0

I imagine you has two functions that move the element (click) and (drag). You can has a variable "onDrag", so you can has some like

<div class="example-box" cdkDrag
  (cdkDragStarted)="onDrag=true"
  (cdkDragEnded)="dragEnded()"
  (click)="!onDrag && click()"
  >
  Drag me around
</div>

Im drag start we put the variable to true, in dragEnded we enclosed in a setTimeOut put the variable to false. the click check first the variable

  onDrag:boolean=false

  click()
  {
    console.log("click")
  }
  dragEnded()
  {
    setTimeout(()=>{
       this.onDrag=false
    })
  }
Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • as I said in my post, the problem only appears when draggable element is wider than container. and it has nothing to do with any (click) event binding... btw, I don`t have any other event than (cdkDragMoved) and (cdkDragEnded) – lambidu Jun 13 '20 at 22:34