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') { // <----- this will always be true
const entry = await item.getAsFileSystemHandle();
if (entry.kind === 'file') {
handleFileEntry(entry);
} else if (entry.kind === 'directory') {
handleDirectoryEntry(entry);
}
}
}
});
I looked further into DataTransfer and found out that whatever you drop file or folder the item.kind is always "file"? why is that?! why isn't it a directory when you drop a folder?
Only way to distinguish this is if you do webkitGetAsEntry() and look at that "entry.kind" instead, or getAsFileSystemHandle in this case... is this a bug?
Ok, so i saw this example in the spec
I looked further into DataTransfer and found out that whatever you drop file or folder the
item.kind
is always"file"
? why is that?! why isn't it a directory when you drop a folder? Only way to distinguish this is if you dowebkitGetAsEntry()
and look at that "entry.kind" instead, or getAsFileSystemHandle in this case... is this a bug?Try it for yourself: drop a folder on this red square: https://jsfiddle.net/sn8bj245/