Skip to content

Commit e086d67

Browse files
authored
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
1 parent ec80e6b commit e086d67

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/desktop/src/file_upload.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,23 @@ impl FileDialogRequest {
7979
let filters: Vec<_> = request
8080
.accept
8181
.as_deref()
82-
.unwrap_or_default()
82+
.unwrap_or(".*")
8383
.split(',')
84-
.filter_map(|s| Filters::from_str(s).ok())
84+
.filter_map(|s| Filters::from_str(s.trim()).ok())
8585
.collect();
8686

8787
let file_extensions: Vec<_> = filters
8888
.iter()
8989
.flat_map(|f| f.as_extensions().into_iter())
9090
.collect();
9191

92-
dialog = dialog.add_filter("name", file_extensions.as_slice());
92+
let filter_name = file_extensions
93+
.iter()
94+
.map(|extension| format!("*.{extension}"))
95+
.collect::<Vec<_>>()
96+
.join(", ");
97+
98+
dialog = dialog.add_filter(filter_name, file_extensions.as_slice());
9399

94100
let files: Vec<_> = if request.multiple {
95101
dialog.pick_files().into_iter().flatten().collect()

0 commit comments

Comments
 (0)