Skip to content

Commit

Permalink
Fix drag and drop example (#357)
Browse files Browse the repository at this point in the history
* Fix drag and drop example

Fixes #356

* Update index.bs
  • Loading branch information
tomayac authored Feb 11, 2022
1 parent b8c1180 commit 2ccefeb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,20 +1796,19 @@ elem.addEventListener('dragover', (e) => {
// Prevent navigation.
e.preventDefault();
});

elem.addEventListener('drop', async (e) => {
// Prevent navigation.
e.preventDefault();

// Process all of the items.
for (const item of e.dataTransfer.items) {
// kind will be 'file' for file/directory entries.
if (item.kind === 'file') {
const entry = await item.getAsFileSystemHandle();
if (entry.kind === 'file') {
handleFileEntry(entry);
} else if (entry.kind === 'directory') {
handleDirectoryEntry(entry);
}
const fileHandlesPromises = [...e.dataTransfer.items]
.filter(item => item.kind === 'file')
.map(item => item.getAsFileSystemHandle());

for await (const handle of fileHandlesPromises) {
if (handle.kind === 'directory') {
console.log(`Directory: ${handle.name}`);
} else {
console.log(`File: ${handle.name}`);
}
}
});
Expand Down

0 comments on commit 2ccefeb

Please sign in to comment.