akserg / ng2-dnd

Angular 2 Drag-and-Drop without dependencies
MIT License
839 stars 252 forks source link

dragOver is not fired #60

Open Maxouhell opened 8 years ago

Maxouhell commented 8 years ago

Report a bug

When I move an element in a list (I use a sortable list), onDragOver isn't fired.

Just create a little list and move elements to see the bug (nothing appear) :

export class AppComponent {
    private datas = [
        {label:'test'},
        {label:'test2'},
        {label:'test3'},
        {label:'test4'},
        {label:'test5'},
    ];

    dragOver(event) {
        alert(event)
    }
 }
<ul dnd-sortable-container [sortableData]="datas" [dropZones]="['test']">
    <li *ngFor="let data of datas; let i = index" dnd-sortable [sortableIndex]="i" (onDragOver)="dragOver($event)">{{data.label}}</li>
</ul>

Event must be fired

Is that a bug, or did I do something wrong ?

aziz-haddad commented 7 years ago

Is this issue still not fixed, because I have the exact same problem

Aalphones commented 7 years ago

Same problem here. Still no fix for this?

jorroll commented 6 years ago

The problem appears to be caused by the fact that sortable._elem !== sortable._sortableDataService.elem when ondragover is called. As far as the component is concerned, when you drag item A over item B, item A's ondragover event is being fired, when instead item B's ondragover event should be fired. I can't find any way of fixing this.

HOWEVER, ondragenter and ondragleave seem to fire normally / correctly. I wanted to manually run change detection whenever a sortable list item is dragged over another one (and update the sorting during dragging). I did something like the following which works:

  @ViewChildren(SortableComponent) sortables: QueryList<SortableComponent>;  

  ngAfterViewInit() {
    this.sortables.toArray().forEach(sortable => {
      sortable._elem.ondragenter = (event) => {
        if ((<any>sortable)._isDropAllowed(event)) {
          sortable._onDragEnterCallback(event);
          this.ref.markForCheck();
        }
      }
    })
  }