question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

missing file upload input/button

See original GitHub issue

Could not find a way to present an upload file button/input using the components provided here (great library btw!)

I’ve been using this and it seems to work well, perhaps a cleaner version could be included:

function UploadButton({label, onUpload, id}) {
  let fileInput = null;
  // If no id was specified, generate a random one
  const uid = id || Math.random().toString(36).substring(7);

  return (
    <span>
      <label htmlFor={uid} className="ui icon button">
        <i className="upload icon"></i>
        {label}
      </label>
      <input type="file" id={uid}
        style={{display: "none"}}
        onChange={() => {
          onUpload(fileInput.files[0]);
        }}
        ref={input => {
          fileInput = input;
        }}
      />
    </span>
  );
} 

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

26reactions
levithomasoncommented, Sep 22, 2017

I think a file button is a bit too specific, the idea you’ve used is a solution.

13reactions
c0rv4xcommented, Sep 20, 2018

@strrel try this one The original is a typescript snippet

import * as React from 'react';
import { Component } from 'react';
import { Button, ButtonProps, Label } from 'semantic-ui-react';
import * as uuid from 'uuid';


export class FileButton extends Component {
    constructor(props) {
        super(props);

        this.id = uuid.v1();
        this.onChangeFile = this.onChangeFile.bind(this);
    }

    render() {
        return (
            <div>
                <Button
                    {...this.props}
                    as="label"
                    htmlFor={this.id} />
                <input
                    hidden
                    id={this.id}
                    multiple
                    type="file"
                    onChange={this.onChangeFile} />
            </div>
        );
    }

    onChangeFile() {
        const fileButton = document.getElementById(this.id);
        const file = fileButton ? fileButton.files[0] : null;
        if (this.props.onSelect) {
            this.props.onSelect(file);
        }
    }
}

export default FileButton;
Read more comments on GitHub >

github_iconTop Results From Across the Web

input type=file show only button
The with "Upload File" text pushes the input control out of view in the wrapper div when it overflows so there is no...
Read more >
"input type=file". File name disappears if there is a post-back
Hi, I have <input type=file runat=server> control on my web page. Once I click the browse button and locate a file, the file...
Read more >
<input type="file"> - HTML: HyperText Markup Language | MDN
A file input's value attribute contains a string that represents the path to the selected file(s). If no file is selected yet, ...
Read more >
File Upload Button is missing
I installed the plugin but when I click on the PDF Form button in the CF7 form, the pop-up windows does not have...
Read more >
Missing File Upload Button
It seems to be a glitch so I have recreated the file upload field in your form. This fixes it. Could you please...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found