ng2draggable icon indicating copy to clipboard operation
ng2draggable copied to clipboard

The draggable handle not working if it contains nested elements

Open alhimik1986 opened this issue 7 years ago • 1 comments

Hello. I suggest to use the following code:

  @HostListener('mousedown', ['$event'])
  onMouseDown(event:MouseEvent) {
    if(event.button === 2)
      return; // prevents right click drag, remove his if you don't want it

    // search the handle in parent elements
    if (this._handle !== undefined) {
      let node = event.target;
      while(true) {
        if ( ! node || node === this._handle)
          break;
        node = node['parentNode'];
      }
      if ( ! node)
        return;
    }

    this.md = true;
    this.topStart = event.clientY - this.element.nativeElement.style.top.replace('px','');
    this.leftStart = event.clientX - this.element.nativeElement.style.left.replace('px','');
  }

I could make a fork but I could not find the repository in github, I suppose the repository is in npmjs. Please update your repository, if the code is normal.

alhimik1986 avatar Jul 19 '17 09:07 alhimik1986

Thanks for this alhimik1986, that code snippet works like a charm!

aprapplicationsupport avatar Aug 09 '17 13:08 aprapplicationsupport