Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:upload): fix upload drag drop will open new tab in firefox 91 and 92 #7190

Merged
merged 4 commits into from Mar 21, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: Document,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Inject(DOCUMENT) private document: Document,
@Inject(DOCUMENT) private document: NzSafeAny,

建议使用 NzSafeAny 来代替,不然可能在 SSR 下会有问题。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipchk 已按建议修改,谢谢~

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(this.document.body, 'drop')
.pipe(takeUntil(this.destroy$))
.subscribe(event => {
event.preventDefault();
event.stopPropagation();
})
);
}

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