Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,29 @@ class AjaxUploader extends Component<UploadProps> {
};

onFileDropOrPaste = async (e: React.DragEvent<HTMLDivElement> | ClipboardEvent) => {
e.preventDefault();

if (e.type === 'dragover') {
return;
}

const { multiple, accept, directory } = this.props;
let items: DataTransferItem[] = [];
let files: File[] = [];
let hasFile: boolean = false;

if (e.type === 'drop') {
const dataTransfer = (e as React.DragEvent<HTMLDivElement>).dataTransfer;
items = [...(dataTransfer.items || [])];
files = [...(dataTransfer.files || [])];
hasFile = items.some(item => item.kind === 'file');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个逻辑和下面的不一样。看起来 hasFile 变量不用定义。直接在下面写 if 就行了,逻辑合并掉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

} else if (e.type === 'paste') {
const clipboardData = (e as ClipboardEvent).clipboardData;
items = [...(clipboardData.items || [])];
files = [...(clipboardData.files || [])];
hasFile = items.some(item => item.kind === 'file') || files.length > 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

test case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

}

if (hasFile) {
e.preventDefault();
}

if (directory) {
Expand Down