fix file selector for IE11

This commit is contained in:
Bruno Windels 2020-11-11 12:47:26 +01:00
parent 8db7499f5a
commit 6384702863

View file

@ -146,6 +146,7 @@ export class Platform {
openFile(mimeType = null) {
const input = document.createElement("input");
input.setAttribute("type", "file");
input.className = "hidden";
if (mimeType) {
input.setAttribute("accept", mimeType);
}
@ -153,6 +154,7 @@ export class Platform {
const checkFile = () => {
input.removeEventListener("change", checkFile, true);
const file = input.files[0];
this._container.removeChild(input);
if (file) {
resolve({name: file.name, blob: BlobHandle.fromFile(file)});
} else {
@ -161,6 +163,8 @@ export class Platform {
}
input.addEventListener("change", checkFile, true);
});
// IE11 needs the input to be attached to the document
this._container.appendChild(input);
input.click();
return promise;
}