Fix allowing multiple files to be dropped onto a single file input (#2359)

Fix a bug that allowed multiple files to be dropped onto a single-file input element

- Fix a bug that allowed multiple files to be dropped onto a single-file input element by accepting only the first file.
This commit is contained in:
Omar Ahmed Hassan 2024-11-29 19:31:14 +02:00 committed by GitHub
parent 25e564154e
commit de23bb702c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -47,14 +47,16 @@ function setupFileInput(chooser) {
const dt = e.dataTransfer;
const files = dt.files;
for (let i = 0; i < files.length; i++) {
allFiles.push(files[i]);
const fileInput = document.getElementById(elementId);
if (fileInput?.hasAttribute("multiple")) {
files.forEach(file => allFiles.push(file));
} else if (fileInput) {
allFiles = [files[0]];
}
const dataTransfer = new DataTransfer();
allFiles.forEach((file) => dataTransfer.items.add(file));
const fileInput = document.getElementById(elementId);
fileInput.files = dataTransfer.files;
if (overlay) {