Skip to content

Commit c6e7bd7

Browse files
fix(module:upload): prevent drop event for firefox only (#8551)
1 parent 21c8b62 commit c6e7bd7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

components/upload/upload.component.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { Direction, Directionality } from '@angular/cdk/bidi';
7+
import { Platform } from '@angular/cdk/platform';
78
import { DOCUMENT, NgClass, NgIf, NgTemplateOutlet } from '@angular/common';
89
import {
910
AfterViewInit,
@@ -21,7 +22,8 @@ import {
2122
Output,
2223
TemplateRef,
2324
ViewChild,
24-
ViewEncapsulation
25+
ViewEncapsulation,
26+
inject
2527
} from '@angular/core';
2628
import { Observable, Subject, Subscription, fromEvent, of } from 'rxjs';
2729
import { filter, takeUntil } from 'rxjs/operators';
@@ -178,6 +180,8 @@ export class NzUploadComponent implements OnInit, AfterViewInit, OnChanges, OnDe
178180
return this;
179181
}
180182

183+
private readonly platform = inject(Platform);
184+
181185
// #endregion
182186

183187
constructor(
@@ -353,15 +357,17 @@ export class NzUploadComponent implements OnInit, AfterViewInit, OnChanges, OnDe
353357
}
354358

355359
ngAfterViewInit(): void {
356-
// fix firefox drop open new tab
357-
this.ngZone.runOutsideAngular(() =>
358-
fromEvent<MouseEvent>(this.document.body, 'drop')
359-
.pipe(takeUntil(this.destroy$))
360-
.subscribe(event => {
361-
event.preventDefault();
362-
event.stopPropagation();
363-
})
364-
);
360+
if (this.platform.FIREFOX) {
361+
// fix firefox drop open new tab
362+
this.ngZone.runOutsideAngular(() =>
363+
fromEvent<MouseEvent>(this.document.body, 'drop')
364+
.pipe(takeUntil(this.destroy$))
365+
.subscribe(event => {
366+
event.preventDefault();
367+
event.stopPropagation();
368+
})
369+
);
370+
}
365371
}
366372

367373
ngOnChanges(): void {

0 commit comments

Comments
 (0)