Skip to content

Commit 9b51874

Browse files
small-ladyalice.zhang
and
alice.zhang
authored
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 <alice.zhang@transn.com>
1 parent 425f8df commit 9b51874

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

components/upload/upload.component.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44
*/
55

66
import { Direction, Directionality } from '@angular/cdk/bidi';
7+
import { DOCUMENT } from '@angular/common';
78
import {
89
ChangeDetectionStrategy,
910
ChangeDetectorRef,
1011
Component,
1112
EventEmitter,
1213
Input,
1314
OnChanges,
15+
AfterViewInit,
1416
OnDestroy,
1517
OnInit,
1618
Optional,
1719
Output,
1820
TemplateRef,
1921
ViewChild,
22+
NgZone,
23+
Inject,
2024
ViewEncapsulation
2125
} from '@angular/core';
22-
import { Observable, of, Subject, Subscription } from 'rxjs';
26+
import { Observable, of, Subject, Subscription, fromEvent } from 'rxjs';
2327
import { filter, takeUntil } from 'rxjs/operators';
2428

2529
import { BooleanInput, NumberInput, NzSafeAny } from 'ng-zorro-antd/core/types';
@@ -52,7 +56,7 @@ import { NzUploadListComponent } from './upload-list.component';
5256
'[class.ant-upload-picture-card-wrapper]': 'nzListType === "picture-card"'
5357
}
5458
})
55-
export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
59+
export class NzUploadComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {
5660
static ngAcceptInputType_nzLimit: NumberInput;
5761
static ngAcceptInputType_nzSize: NumberInput;
5862
static ngAcceptInputType_nzDirectory: BooleanInput;
@@ -175,6 +179,8 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
175179
// #endregion
176180

177181
constructor(
182+
private ngZone: NgZone,
183+
@Inject(DOCUMENT) private document: NzSafeAny,
178184
private cdr: ChangeDetectorRef,
179185
private i18n: NzI18nService,
180186
@Optional() private directionality: Directionality
@@ -344,6 +350,18 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
344350
});
345351
}
346352

353+
ngAfterViewInit(): void {
354+
// fix firefox drop open new tab
355+
this.ngZone.runOutsideAngular(() =>
356+
fromEvent<MouseEvent>(this.document.body, 'drop')
357+
.pipe(takeUntil(this.destroy$))
358+
.subscribe(event => {
359+
event.preventDefault();
360+
event.stopPropagation();
361+
})
362+
);
363+
}
364+
347365
ngOnChanges(): void {
348366
this.zipOptions().setClassMap();
349367
}

0 commit comments

Comments
 (0)