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