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 1 commit
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
14 changes: 13 additions & 1 deletion components/upload/upload.component.ts
Expand Up @@ -11,6 +11,7 @@ import {
EventEmitter,
Input,
OnChanges,
AfterViewInit,
OnDestroy,
OnInit,
Optional,
Expand Down Expand Up @@ -52,7 +53,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 @@ -328,6 +329,12 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
this.cdr.detectChanges();
}

// fix firefox drop open new tab
private handleDropOpenNewTab(e: DragEvent){
e.preventDefault();
e.stopPropagation()
}

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
// fix firefox drop open new tab
private handleDropOpenNewTab(e: DragEvent){
e.preventDefault();
e.stopPropagation()
}

// #endregion

ngOnInit(): void {
Expand All @@ -344,12 +351,17 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
});
}

ngAfterViewInit(): void {
document.body.addEventListener('drop', this.handleDropOpenNewTab);
}
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
ngAfterViewInit(): void {
document.body.addEventListener('drop', this.handleDropOpenNewTab);
}
constructor(private ngZone: NgZone, @Inject(DOCUMENT) private document: Document) {}
ngAfterViewInit(): void {
this.ngZone.runOutsideAngular(() => fromEvent(this.document.body, 'drop').pipe(takeUntil(this.destroy$)).subscribe(event => {
event.preventDefault();
event.stopPropagation();
}));
}


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

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
document.body.removeEventListener('drop', this.handleDropOpenNewTab)
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
document.body.removeEventListener('drop', this.handleDropOpenNewTab)

}
}