Skip to content

Commit 05eab2b

Browse files
committed
🔧 Improve file dialog opening: use overlay input approach
- Use absolutely positioned transparent file input over upload area - Remove label wrapper approach - Input covers entire upload area with opacity 0 - Better browser compatibility for opening file dialog - Save app instance to window for testing - Update cache-busting to v=5
1 parent 87b8345 commit 05eab2b

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

docs/assets/app.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,16 @@ class App {
183183
}
184184

185185
setupEventListeners() {
186-
// Click to upload - use label approach for better browser compatibility
187-
// The label wraps the file input, so clicking anywhere on upload area triggers it
188-
const fileInputLabel = this.uploadArea.querySelector('.file-input-label');
189-
if (fileInputLabel) {
190-
// Make label cover entire upload area
191-
fileInputLabel.style.position = 'absolute';
192-
fileInputLabel.style.top = '0';
193-
fileInputLabel.style.left = '0';
194-
fileInputLabel.style.width = '100%';
195-
fileInputLabel.style.height = '100%';
196-
fileInputLabel.style.cursor = 'pointer';
197-
fileInputLabel.style.zIndex = '1';
198-
// Ensure label is clickable
199-
fileInputLabel.style.pointerEvents = 'auto';
200-
}
201-
202-
// Direct click handler on upload area as primary method
186+
// File input is positioned absolutely over upload area, so clicking anywhere opens it
187+
// Also handle direct clicks on upload area as fallback
203188
this.uploadArea.addEventListener('click', (e) => {
204189
// Don't trigger if clicking on remove button or other interactive elements
205190
if (e.target.closest('.remove-file') || e.target.closest('.btn')) {
206191
return;
207192
}
208-
// Trigger file input click directly
209-
if (this.fileInput && e.target !== this.fileInput) {
210-
// Small delay to ensure event propagation
193+
// If click is not on file input itself, trigger it
194+
if (this.fileInput && e.target !== this.fileInput && !e.target.closest('input[type="file"]')) {
195+
// Use setTimeout for better compatibility
211196
setTimeout(() => {
212197
try {
213198
this.fileInput.click();
@@ -223,7 +208,8 @@ class App {
223208
if (e.target.closest('.remove-file') || e.target.closest('.btn')) {
224209
return;
225210
}
226-
if (this.fileInput && e.target !== this.fileInput) {
211+
if (this.fileInput && e.target !== this.fileInput && !e.target.closest('input[type="file"]')) {
212+
// Prevent default to avoid conflicts
227213
e.preventDefault();
228214
setTimeout(() => {
229215
try {
@@ -575,7 +561,7 @@ async function init() {
575561
// Load JSZip and initialize app
576562
await loadJSZip();
577563
window.JSZip = JSZip;
578-
new App();
564+
window.app = new App(); // Save app instance for testing
579565
} catch (error) {
580566
console.error('Failed to initialize:', error);
581567
const errorDiv = document.createElement('div');

docs/assets/style.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ body {
177177
z-index: 2;
178178
}
179179

180-
.file-input-label {
181-
display: block;
182-
width: 100%;
183-
height: 100%;
180+
.file-input-hidden {
184181
position: absolute;
185182
top: 0;
186183
left: 0;
184+
width: 100%;
185+
height: 100%;
186+
opacity: 0;
187187
cursor: pointer;
188-
z-index: 1;
188+
z-index: 10;
189+
font-size: 0;
189190
}
190191

191192
.upload-icon {

docs/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ <h2>Upload Your Documents</h2>
4343
</p>
4444
<p class="upload-hint">Supports: .txt, .docx files</p>
4545
</div>
46-
<label for="fileInput" class="file-input-label">
47-
<input type="file" id="fileInput" multiple accept=".txt,.docx" style="position: absolute; width: 0; height: 0; opacity: 0; overflow: hidden;">
48-
</label>
46+
<input type="file" id="fileInput" multiple accept=".txt,.docx" class="file-input-hidden">
4947
</div>
5048

5149
<div id="fileList" class="file-list"></div>

0 commit comments

Comments
 (0)