From e086d6765bcbc80a2965faf130de81f5957ffe0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20V=C3=A1squez?=
<95881408+jjvn84@users.noreply.github.com>
Date: Fri, 20 Jun 2025 00:16:31 -0400
Subject: [PATCH] Fixes issue with the file dialog showing only folders and not
files (#4177)
* Fixes issue with the file dialog showing only folders and not files when the element has no "accept" attribute.
* Handle spaces between file extensions in the accept attribute of file type input elements
---
packages/desktop/src/file_upload.rs | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/packages/desktop/src/file_upload.rs b/packages/desktop/src/file_upload.rs
index 5448586d3..94c88d6a3 100644
--- a/packages/desktop/src/file_upload.rs
+++ b/packages/desktop/src/file_upload.rs
@@ -79,9 +79,9 @@ impl FileDialogRequest {
let filters: Vec<_> = request
.accept
.as_deref()
- .unwrap_or_default()
+ .unwrap_or(".*")
.split(',')
- .filter_map(|s| Filters::from_str(s).ok())
+ .filter_map(|s| Filters::from_str(s.trim()).ok())
.collect();
let file_extensions: Vec<_> = filters
@@ -89,7 +89,13 @@ impl FileDialogRequest {
.flat_map(|f| f.as_extensions().into_iter())
.collect();
- dialog = dialog.add_filter("name", file_extensions.as_slice());
+ let filter_name = file_extensions
+ .iter()
+ .map(|extension| format!("*.{extension}"))
+ .collect::>()
+ .join(", ");
+
+ dialog = dialog.add_filter(filter_name, file_extensions.as_slice());
let files: Vec<_> = if request.multiple {
dialog.pick_files().into_iter().flatten().collect()