top | item 17767102

(no title)

iris-digital | 7 years ago

> input button is hidden using CSS tricks because the actual button can't be styled.

Buttons can be styled.

discuss

order

vinceguidry|7 years ago

Not the file input button, unless things have changed in the last year since I had to build one. Other buttons, sure, but not on file inputs.

megous|7 years ago

You realize you don't need input field for file input in any of the modern browsers. Just capture the click event and create input field temporarily.

    let i = document.createElement('input');
    i.type = 'file';
    // other attributes if you like
    i.onselect = ev => {
      // ev.files contains selected files
    };
    i.click();
    i.remove();
No stupid styling hacks needed. At most you may need tabIndex on the <a> or <div> that represents the button for selecting files.

You can leave <input type=file> around if you want to submit data via <form> and not via XHR.

jandrese|7 years ago

Heaven forbid your buttons look like buttons.

baddox|7 years ago

Not filepicker inputs. They are notoriously difficult to style consistently across browsers.