From 9b518742e3be8c85c0b2e2e66d4ffe108e43a2d0 Mon Sep 17 00:00:00 2001 From: small-lady <13277951908@163.com> Date: Mon, 21 Mar 2022 10:37:16 +0800 Subject: [PATCH] fix(module:upload): fix upload drag drop will open new tab in firefox 91 and 92 (#7190) * fix: nz-upload drag drop will open new tab when use firefox versions 91 and 92 * fix:nz-upload drag drop will open new tab when use firefox versions in 91 and 92 * fix: nz-upload drag drop will open new tab when use firefox versions in 91 and 92 * fix: nz-upload modify document type is NzSafeAny Co-authored-by: alice.zhang --- components/upload/upload.component.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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(); }