Skip to content

Commit 74a629a

Browse files
committed
fix: check for support of partly supported webkitGetAsEntry
if the browser supports `webkitGetAsEntry`, we can also read through directories, but if not, we better skip dropped directories entirely
1 parent e75931d commit 74a629a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

packages/uui-file-dropzone/lib/uui-file-dropzone.element.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
111111
): Promise<File[]> {
112112
const fileEntries: File[] = [];
113113
// Use BFS to traverse entire directory/file structure
114-
const queue = [];
115-
for (let i = 0; i < dataTransferItemList.length; i++) {
116-
queue.push(dataTransferItemList[i].webkitGetAsEntry());
117-
}
114+
const queue = [...dataTransferItemList];
118115

119116
const acceptList: string[] = [];
120117
const wildcards: string[] = [];
@@ -141,6 +138,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
141138
fileEntries.push(file);
142139
}
143140
} else if (entry.kind === 'directory') {
141+
if ('webkitGetAsEntry' in entry === false) continue;
144142
const directory = entry.webkitGetAsEntry()! as FileSystemDirectoryEntry;
145143
queue.push(
146144
...(await this._readAllDirectoryEntries(directory.createReader()))
@@ -209,7 +207,7 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
209207
if (items) {
210208
let result = await this._getAllFileEntries(items);
211209

212-
if (this.multiple === false && result.length > 0) {
210+
if (this.multiple === false && result.length) {
213211
result = [result[0]];
214212
}
215213

0 commit comments

Comments
 (0)