Skip to content

Commit 87b8345

Browse files
committed
🔧 Improve file dialog opening with multiple approaches
- Add both label wrapper and direct click handlers - Add mousedown event for better browser compatibility - Improve label styling to cover entire upload area - Add overflow: hidden to upload area - Better error handling for file dialog opening - Update cache-busting to v=5
1 parent bf3bcb7 commit 87b8345

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

docs/assets/app.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,43 @@ class App {
195195
fileInputLabel.style.height = '100%';
196196
fileInputLabel.style.cursor = 'pointer';
197197
fileInputLabel.style.zIndex = '1';
198+
// Ensure label is clickable
199+
fileInputLabel.style.pointerEvents = 'auto';
198200
}
199201

200-
// Also handle clicks on upload area as fallback
202+
// Direct click handler on upload area as primary method
201203
this.uploadArea.addEventListener('click', (e) => {
202204
// Don't trigger if clicking on remove button or other interactive elements
203205
if (e.target.closest('.remove-file') || e.target.closest('.btn')) {
204206
return;
205207
}
206-
// Trigger file input click if label didn't work
207-
if (this.fileInput && e.target !== this.fileInput && !e.target.closest('label')) {
208-
// Use setTimeout for better compatibility
208+
// Trigger file input click directly
209+
if (this.fileInput && e.target !== this.fileInput) {
210+
// Small delay to ensure event propagation
209211
setTimeout(() => {
210-
this.fileInput.click();
211-
}, 0);
212+
try {
213+
this.fileInput.click();
214+
} catch (err) {
215+
console.error('Error opening file dialog:', err);
216+
}
217+
}, 10);
218+
}
219+
});
220+
221+
// Also handle mousedown for better compatibility
222+
this.uploadArea.addEventListener('mousedown', (e) => {
223+
if (e.target.closest('.remove-file') || e.target.closest('.btn')) {
224+
return;
225+
}
226+
if (this.fileInput && e.target !== this.fileInput) {
227+
e.preventDefault();
228+
setTimeout(() => {
229+
try {
230+
this.fileInput.click();
231+
} catch (err) {
232+
console.error('Error opening file dialog:', err);
233+
}
234+
}, 10);
212235
}
213236
});
214237

docs/assets/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ body {
154154
align-items: center;
155155
justify-content: center;
156156
position: relative;
157+
overflow: hidden;
157158
}
158159

159160
.upload-area:hover {
@@ -180,6 +181,11 @@ body {
180181
display: block;
181182
width: 100%;
182183
height: 100%;
184+
position: absolute;
185+
top: 0;
186+
left: 0;
187+
cursor: pointer;
188+
z-index: 1;
183189
}
184190

185191
.upload-icon {

0 commit comments

Comments
 (0)