Skip to content

Commit

Permalink
fix: check for support of partly supported webkitGetAsEntry
Browse files Browse the repository at this point in the history
if the browser supports `webkitGetAsEntry`, we can also read through directories, but if not, we better skip dropped directories entirely
  • Loading branch information
iOvergaard committed May 12, 2023
1 parent e75931d commit 74a629a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/uui-file-dropzone/lib/uui-file-dropzone.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
): Promise<File[]> {
const fileEntries: File[] = [];
// Use BFS to traverse entire directory/file structure
const queue = [];
for (let i = 0; i < dataTransferItemList.length; i++) {
queue.push(dataTransferItemList[i].webkitGetAsEntry());
}
const queue = [...dataTransferItemList];

const acceptList: string[] = [];
const wildcards: string[] = [];
Expand All @@ -141,6 +138,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
fileEntries.push(file);
}
} else if (entry.kind === 'directory') {
if ('webkitGetAsEntry' in entry === false) continue;
const directory = entry.webkitGetAsEntry()! as FileSystemDirectoryEntry;
queue.push(
...(await this._readAllDirectoryEntries(directory.createReader()))
Expand Down Expand Up @@ -209,7 +207,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
if (items) {
let result = await this._getAllFileEntries(items);

if (this.multiple === false && result.length > 0) {
if (this.multiple === false && result.length) {
result = [result[0]];
}

Expand Down

0 comments on commit 74a629a

Please sign in to comment.