File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,10 +63,10 @@ const initialPosition = {
6363 </ul>
6464 <div
6565 class="ant-image-preview-img-wrapper"
66+ #imagePreviewWrapper
6667 cdkDrag
6768 [style.transform]="previewImageWrapperTransform"
6869 [cdkDragFreeDragPosition]="position"
69- (mousedown)="onDragStarted()"
7070 (cdkDragReleased)="onDragReleased()"
7171 >
7272 <ng-container *ngFor="let image of images; index as imageIndex">
@@ -176,6 +176,7 @@ export class NzImagePreviewComponent implements OnInit {
176176 closeClick = new EventEmitter < void > ( ) ;
177177
178178 @ViewChild ( 'imgRef' ) imageRef ! : ElementRef < HTMLImageElement > ;
179+ @ViewChild ( 'imagePreviewWrapper' , { static : true } ) imagePreviewWrapper ! : ElementRef < HTMLElement > ;
179180
180181 private zoom : number ;
181182 private rotate : number ;
@@ -214,6 +215,12 @@ export class NzImagePreviewComponent implements OnInit {
214215 this . ngZone . run ( ( ) => this . containerClick . emit ( ) ) ;
215216 }
216217 } ) ;
218+
219+ fromEvent ( this . imagePreviewWrapper . nativeElement , 'mousedown' )
220+ . pipe ( takeUntil ( this . destroy$ ) )
221+ . subscribe ( ( ) => {
222+ this . isDragging = true ;
223+ } ) ;
217224 } ) ;
218225 }
219226
@@ -319,10 +326,6 @@ export class NzImagePreviewComponent implements OnInit {
319326 this . cdr . markForCheck ( ) ;
320327 }
321328
322- onDragStarted ( ) : void {
323- this . isDragging = true ;
324- }
325-
326329 onDragReleased ( ) : void {
327330 this . isDragging = false ;
328331 const width = this . imageRef . nativeElement . offsetWidth * this . zoom ;
Original file line number Diff line number Diff line change @@ -443,11 +443,12 @@ describe('Preview', () => {
443443 it ( 'should drag released work' , fakeAsync ( ( ) => {
444444 context . images = [ { src : QUICK_SRC } ] ;
445445 context . createUsingService ( ) ;
446- const previewInstance = context . previewRef ?. previewInstance ;
446+ const previewInstance = context . previewRef ?. previewInstance ! ;
447447 tickChanges ( ) ;
448- previewInstance ?. onDragStarted ( ) ;
449- previewInstance ?. onDragReleased ( ) ;
450- expect ( previewInstance ?. position ) . toEqual ( { x : 0 , y : 0 } ) ;
448+ previewInstance . imagePreviewWrapper . nativeElement . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
449+ expect ( previewInstance . isDragging ) . toEqual ( true ) ;
450+ previewInstance . onDragReleased ( ) ;
451+ expect ( previewInstance . position ) . toEqual ( { x : 0 , y : 0 } ) ;
451452 } ) ) ;
452453
453454 it ( 'should position calculate correct' , ( ) => {
You can’t perform that action at this time.
0 commit comments