alessandro gaboardi alessandro gaboardi - 11 months ago 60
iOS Question

Polymer click re-route on iOS

I'm using a hidden

<input id="mfile" type="file" accept="image/*">

and triggering it with a paper-fab from google's element catalog. It works everywhere except for safari on iOS, the click fires but it doesn't get redirected to the input.

By redirect i mean a on-tap listener on the fab that triggers

Any suggestion or workaround?

Answer Source

Thanks to @marx_tseng from polymer slack, here is the solution:

<paper-fab id="fileFab" label="File" on-tap="_pickFile"></paper-fab>
<input type="file" id="filePicker" hidden />


_pickFile: function(e) {

    // cancelable is true, not work on ios simulator
    // this.$;

    // default cancelable is false, work on ios simulator
    try {
        // fixes mobile safari
        var evt = new MouseEvent("click");
    } catch (e) {
        // fallback for IE11