Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file input webkitdirectory on android #2510

Open
jimmywarting opened this issue Mar 12, 2020 · 1 comment
Open

file input webkitdirectory on android #2510

jimmywarting opened this issue Mar 12, 2020 · 1 comment

Comments

@jimmywarting
Copy link

detecting directory support is flaky on mobile.

var input = document.createElement('input')
input.type = 'file'
alert('webkitdirectory' in input)

my chrome browser on android yields true - but selecting a folder isn't possible.
however it lets me pick files instead.

I would have been fine with a grateful degration or a progressive enhancement. But upon selecting files the input.files.length is still 0. So the change event won't even fire.

anyone have any suggestions?

@jimmywarting
Copy link
Author

jimmywarting commented Mar 12, 2020

i figured maybe it wouldn't be possible to alter the filelist somehow if the webkitdirectory was added

function FileListItem(a) {
  a = [].slice.call(Array.isArray(a) ? a : arguments)
  for (var c, b = c = a.length, d = !0; b-- && d;) d = a[b] instanceof File
  if (!d) throw new TypeError("expected argument to FileList is File or array of File objects")
  for (b = (new ClipboardEvent("")).clipboardData || new DataTransfer; c--;) b.items.add(a[c])
  return b.files
}

var files = [
  new File(['content'], 'sample1.txt'),
  new File(['abc'], 'sample2.txt')
];
input.webkitdirectory = true
input.files = new FileListItem(files)
input.files.length === 2 // detection fail expected it to be 0 to match manual test result 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant