Browse Source

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 <input> element has no "accept" attribute.

* Handle spaces between file extensions in the accept attribute of file type input elements
Juan Vásquez 1 week ago
parent
commit
e086d6765b
1 changed files with 9 additions and 3 deletions
  1. 9 3
      packages/desktop/src/file_upload.rs

+ 9 - 3
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::<Vec<_>>()
+                .join(", ");
+
+            dialog = dialog.add_filter(filter_name, file_extensions.as_slice());
 
             let files: Vec<_> = if request.multiple {
                 dialog.pick_files().into_iter().flatten().collect()