diff --git a/components/upload/upload.component.ts b/components/upload/upload.component.ts index eeaf42064d..e6d833ea7f 100644 --- a/components/upload/upload.component.ts +++ b/components/upload/upload.component.ts @@ -4,6 +4,7 @@ */ import { Direction, Directionality } from '@angular/cdk/bidi'; +import { DOCUMENT } from '@angular/common'; import { ChangeDetectionStrategy, ChangeDetectorRef, @@ -11,15 +12,18 @@ import { EventEmitter, Input, OnChanges, + AfterViewInit, OnDestroy, OnInit, Optional, Output, TemplateRef, ViewChild, + NgZone, + Inject, ViewEncapsulation } from '@angular/core'; -import { Observable, of, Subject, Subscription } from 'rxjs'; +import { Observable, of, Subject, Subscription, fromEvent } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; import { BooleanInput, NumberInput, NzSafeAny } from 'ng-zorro-antd/core/types'; @@ -52,7 +56,7 @@ import { NzUploadListComponent } from './upload-list.component'; '[class.ant-upload-picture-card-wrapper]': 'nzListType === "picture-card"' } }) -export class NzUploadComponent implements OnInit, OnChanges, OnDestroy { +export class NzUploadComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy { static ngAcceptInputType_nzLimit: NumberInput; static ngAcceptInputType_nzSize: NumberInput; static ngAcceptInputType_nzDirectory: BooleanInput; @@ -175,6 +179,8 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy { // #endregion constructor( + private ngZone: NgZone, + @Inject(DOCUMENT) private document: NzSafeAny, private cdr: ChangeDetectorRef, private i18n: NzI18nService, @Optional() private directionality: Directionality @@ -344,6 +350,18 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy { }); } + ngAfterViewInit(): void { + // fix firefox drop open new tab + this.ngZone.runOutsideAngular(() => + fromEvent(this.document.body, 'drop') + .pipe(takeUntil(this.destroy$)) + .subscribe(event => { + event.preventDefault(); + event.stopPropagation(); + }) + ); + } + ngOnChanges(): void { this.zipOptions().setClassMap(); }