1
1
import {
2
2
AfterViewInit ,
3
+ ContentChild ,
3
4
Directive ,
4
5
ElementRef ,
5
6
EventEmitter ,
@@ -23,6 +24,7 @@ import {NgsgReflectService} from './sort/reflection/ngsg-reflect.service';
23
24
import { NgsgSortService } from './sort/sort/ngsg-sort.service' ;
24
25
import { NgsgStoreService } from './store/ngsg-store.service' ;
25
26
import { NgsgClassService } from './helpers/class/ngsg-class.service' ;
27
+ import { NgsgDragHandleDirective } from './ngsg-drag-handle.directive' ;
26
28
27
29
const selector = '[ngSortgridItem]' ;
28
30
@@ -37,6 +39,9 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
37
39
38
40
@Output ( ) sorted = new EventEmitter < NgsgOrderChange < any > > ( ) ;
39
41
42
+ @ContentChild ( NgsgDragHandleDirective ) handle : NgsgDragHandleDirective ;
43
+
44
+ private handleElement : HTMLElement ;
40
45
private selected = false ;
41
46
private destroy$ = new Subject ( ) ;
42
47
@@ -82,7 +87,14 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
82
87
}
83
88
84
89
ngAfterViewInit ( ) : void {
85
- this . el . nativeElement . draggable = true ;
90
+ this . handleElement = this . handle ?. el ?. nativeElement || this . el . nativeElement ;
91
+
92
+ fromEvent < DragEvent > ( this . handleElement , 'mousedown' ) . pipe (
93
+ takeUntil ( this . destroy$ )
94
+ ) . subscribe ( ( ) => {
95
+ this . el . nativeElement . draggable = true ;
96
+ }
97
+ ) ;
86
98
}
87
99
88
100
ngOnDestroy ( ) : void {
@@ -119,6 +131,7 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
119
131
120
132
@HostListener ( 'dragend' )
121
133
drop ( ) : void {
134
+ this . el . nativeElement . draggable = false ;
122
135
if ( ! this . ngsgStore . hasSelectedItems ( this . ngSortGridGroup ) ) {
123
136
return ;
124
137
}
0 commit comments