Skip to content

Commit

Permalink
fix dragItemListeners setup
Browse files Browse the repository at this point in the history
  • Loading branch information
wouter-willems committed Dec 16, 2024
1 parent 4a34afc commit d8f4fd9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 2 additions & 0 deletions projects/demo/src/app/demo/demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
<klp-form-file-input style="height: 100%;" [(ngModel)]="myfile" [multiple]="false" [onlyShowUploadButton]="false" (ngModelChange)="fileSelected($event)" [useFullParentSize]="false"></klp-form-file-input>
<klp-form-button (click)="toggie()">clickie</klp-form-button>
grouped items {{groupedItems | json}}


<klp-form-sortable-items [(ngModel)]="sortableItems">
<ng-template let-item="item">
{{item}}
Expand Down
2 changes: 1 addition & 1 deletion projects/klippa/ngx-enhancy-forms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@klippa/ngx-enhancy-forms",
"version": "18.25.3",
"version": "18.25.4",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ export class SortableItemsComponent
}

ngAfterViewInit(): void {
this.setDragItemListeners();
this.dragItems.changes.subscribe(() => {
this.dragItems.forEach(e => {
this.ngZone.runOutsideAngular(() => {
e.nativeElement.removeEventListener('dragstart', this.onDragStart);
e.nativeElement.removeEventListener('dragover', this.onDragOver);
e.nativeElement.removeEventListener('dragenter', this.onDragEnter);
e.nativeElement.removeEventListener('dragend', this.onDragEnd);

e.nativeElement.addEventListener('dragstart', this.onDragStart);
e.nativeElement.addEventListener('dragover', this.onDragOver);
e.nativeElement.addEventListener('dragenter', this.onDragEnter);
e.nativeElement.addEventListener('dragend', this.onDragEnd);

this.dragItems.forEach((dragItem, i) => {
dragItem.nativeElement.querySelector('.visual').style.transform = `translateY(0%)`;
});
this.setDragItemListeners();
});
}

});
private setDragItemListeners(): void {
this.dragItems.forEach(e => {
this.ngZone.runOutsideAngular(() => {
e.nativeElement.removeEventListener('dragstart', this.onDragStart);
e.nativeElement.removeEventListener('dragover', this.onDragOver);
e.nativeElement.removeEventListener('dragenter', this.onDragEnter);
e.nativeElement.removeEventListener('dragend', this.onDragEnd);

e.nativeElement.addEventListener('dragstart', this.onDragStart);
e.nativeElement.addEventListener('dragover', this.onDragOver);
e.nativeElement.addEventListener('dragenter', this.onDragEnter);
e.nativeElement.addEventListener('dragend', this.onDragEnd);

e.nativeElement.querySelector('.visual').style.transform = `translateY(0%)`;
});
});
}
Expand Down

0 comments on commit d8f4fd9

Please sign in to comment.