fix(chat): keep the file input in the layout so the picker opens

This commit is contained in:
2026-10-29 19:58:51 +00:00
parent a828c44ce9
commit 0c5816bb08
@@ -18,7 +18,15 @@ Future<List<ChatPickedFile>?> _selectFiles() {
final input = web.HTMLInputElement()
..type = 'file'
..multiple = true;
input.style.display = 'none';
// Keep the input in the layout but out of sight: a display:none file input
// is refused by some browsers when click() runs outside the picker gesture.
input.style
..position = 'fixed'
..left = '-10000px'
..top = '0'
..width = '1px'
..height = '1px'
..opacity = '0';
final completer = Completer<List<ChatPickedFile>?>();
@@ -56,12 +64,18 @@ Future<List<ChatPickedFile>?> _selectFiles() {
}
}
input.addEventListener('change', ((web.Event _) {
unawaited(readSelection());
}).toJS);
input.addEventListener('cancel', ((web.Event _) {
finish(null);
}).toJS);
input.addEventListener(
'change',
((web.Event _) {
unawaited(readSelection());
}).toJS,
);
input.addEventListener(
'cancel',
((web.Event _) {
finish(null);
}).toJS,
);
final body = web.document.body;
if (body == null) return Future.value(null);