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
This commit is contained in:
1 parent
ec80e6bd37
commit
e086d6765b
1 file changed
+9
-3
@@ -79,9 +79,9 @@ impl FileDialogRequest {
|
|||||||
let filters: Vec<_> = request
|
let filters: Vec<_> = request
|
||||||
.accept
|
.accept
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.unwrap_or_default()
|
.unwrap_or(".*")
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter_map(|s| Filters::from_str(s).ok())
|
.filter_map(|s| Filters::from_str(s.trim()).ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let file_extensions: Vec<_> = filters
|
let file_extensions: Vec<_> = filters
|
||||||
@@ -89,7 +89,13 @@ impl FileDialogRequest {
|
|||||||
.flat_map(|f| f.as_extensions().into_iter())
|
.flat_map(|f| f.as_extensions().into_iter())
|
||||||
.collect();
|
.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 {
|
let files: Vec<_> = if request.multiple {
|
||||||
dialog.pick_files().into_iter().flatten().collect()
|
dialog.pick_files().into_iter().flatten().collect()
|
||||||
|
|||||||
Reference in new issue
Block a user