wubocong / react-upload-file

react upload component
MIT License
28 stars 25 forks source link

chooseFileButton's <YourChooseButton /> can't show #1

Closed jingxinxin closed 7 years ago

jingxinxin commented 7 years ago

<ReactUploadFile options={uploadFileOptions} chooseFileButton={\} uploadFileButton={\<Button color='green' content='上传' icon="upload"/>}/> \ can't show . Button is myself component

wubocong commented 7 years ago

@jingxinxin Can you give me the full content of this file for debug, thx!

v-zaburdaev commented 7 years ago

I have a same problem. The childs of <Button></Button>replaced by hidden element <input type="file" name="ajax-upload-file-input" accept="image/*" multiple="" style="display: none;">

It needs to create special class for right rendering child and catch onClick event. My example: import React from "react"; import {Button} from "react-bootstrap";

class UploadButton extends React.Component {
    constructor(props) {
        super(props);
    }
    onclick(e){
        this.props.onClick(e);
    }
    render(){
        return <Button onClick={this.onclick.bind(this)}>Upload files
          **{this.props.children}**</Button>;
    }
}

UploadButton.propTypes = {
    children: React.PropTypes.array.isRequired,
    onClick: React.PropTypes.func.isRequired
};

export default UploadButton;

You can read childs of chooseFileButton element and add element to his childrens.

slxiao commented 7 years ago

@jingxinxin I met the same issue

vstlouis commented 7 years ago

You need to return <button> and not <Button> from this component.

wubocong commented 7 years ago

@v-zaburdaev You are right, i will improve this.