Skip to content

Commit 669637f

Browse files
committed
Fix issues introduced with AimWhy@b6e855d
1 parent b6e855d commit 669637f

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browser-fs-access",
3-
"version": "0.36.0",
3+
"version": "0.37.0",
44
"description": "File System Access API with legacy fallback in the browser.",
55
"type": "module",
66
"source": "./src/index.js",

src/legacy/directory-open.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ export default async (options = [{}]) => {
2929
const input = document.createElement('input');
3030
input.type = 'file';
3131
input.webkitdirectory = true;
32+
// Append to the DOM, else Safari on iOS won't fire the `change` event
33+
// reliably.
34+
input.style.display = 'none';
35+
document.body.append(input);
3236

3337
input.addEventListener('cancel', () => {
3438
input.remove();
3539
reject(new DOMException('The user aborted a request.', 'AbortError'));
3640
});
3741

3842
input.addEventListener('change', () => {
43+
input.remove();
3944
let files = Array.from(input.files);
4045
if (!options[0].recursive) {
4146
files = files.filter((file) => {

src/legacy/file-open.mjs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,15 @@ export default async (options = [{}]) => {
3737
// reliably.
3838
input.style.display = 'none';
3939
document.body.append(input);
40-
const _reject = () => cleanupListenersAndMaybeReject(reject);
41-
const _resolve = (value) => {
42-
if (typeof cleanupListenersAndMaybeReject === 'function') {
43-
cleanupListenersAndMaybeReject();
44-
}
45-
resolve(value);
46-
};
4740

4841
input.addEventListener('cancel', () => {
4942
input.remove();
5043
reject(new DOMException('The user aborted a request.', 'AbortError'));
5144
});
5245

5346
input.addEventListener('change', () => {
54-
window.removeEventListener('focus', cancelDetector);
5547
input.remove();
56-
_resolve(input.multiple ? Array.from(input.files) : input.files[0]);
48+
resolve(input.multiple ? Array.from(input.files) : input.files[0]);
5749
});
5850

5951
if ('showPicker' in HTMLInputElement.prototype) {

0 commit comments

Comments
 (0)