Skip to content

Commit

Permalink
fix(module:upload): fix upload drag drop will open new tab in firefox…
Browse files Browse the repository at this point in the history
… 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 <alice.zhang@transn.com>
  • Loading branch information
small-lady and alice.zhang committed Mar 21, 2022
1 parent 425f8df commit 9b51874
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions components/upload/upload.component.ts
Expand Up @@ -4,22 +4,26 @@
*/

import { Direction, Directionality } from '@angular/cdk/bidi';
import { DOCUMENT } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -344,6 +350,18 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
});
}

ngAfterViewInit(): void {
// fix firefox drop open new tab
this.ngZone.runOutsideAngular(() =>
fromEvent<MouseEvent>(this.document.body, 'drop')
.pipe(takeUntil(this.destroy$))
.subscribe(event => {
event.preventDefault();
event.stopPropagation();
})
);
}

ngOnChanges(): void {
this.zipOptions().setClassMap();
}
Expand Down

0 comments on commit 9b51874

Please sign in to comment.