Fix file dialog double-open: add stopPropagation and reset input value

This commit is contained in:
Кирилл Блинов 2026-05-29 12:34:11 +03:00
parent 5e62b3d308
commit 6f727b1f3d

View File

@ -73,17 +73,26 @@ class TranscriptionApp {
const fileInput = document.getElementById('fileInput'); const fileInput = document.getElementById('fileInput');
const browseLink = document.querySelector('.browse-link'); const browseLink = document.querySelector('.browse-link');
// Click to browse // Click on browse link (stop propagation to avoid double click)
browseLink.addEventListener('click', () => fileInput.click()); browseLink.addEventListener('click', (e) => {
dropZone.addEventListener('click', (e) => { e.stopPropagation();
if (e.target === dropZone || e.target.closest('.drop-zone-content')) { fileInput.click();
fileInput.click();
}
}); });
// File input change // Click on drop zone (but not on the file input itself)
dropZone.addEventListener('click', (e) => {
if (e.target === fileInput) return;
fileInput.click();
});
// File input change - reset value after handling
fileInput.addEventListener('change', (e) => { fileInput.addEventListener('change', (e) => {
this.handleFiles(e.target.files); const files = e.target.files;
if (files.length) {
this.handleFiles(files);
}
// Reset so the same file can be selected again
fileInput.value = '';
}); });
// Drag & drop // Drag & drop