Move inputFile ref to WriteDataForm

pull/10616/head
Andrew Watkins 2017-06-22 15:50:03 -07:00
parent 870deff124
commit 734a54708c
2 changed files with 46 additions and 46 deletions

View File

@ -10,10 +10,9 @@ const WriteDataBody = ({
uploadContent, uploadContent,
fileName, fileName,
isManual, isManual,
}) => { fileInput,
let inputRef handleFileOpen,
}) => (
return (
<div className="write-data-form--body"> <div className="write-data-form--body">
{isManual {isManual
? <textarea ? <textarea
@ -30,13 +29,10 @@ const WriteDataBody = ({
type="file" type="file"
onChange={e => handleFile(e, false)} onChange={e => handleFile(e, false)}
className="write-data-form--upload" className="write-data-form--upload"
ref={r => (inputRef = r)} ref={fileInput}
accept="text/*, application/gzip" accept="text/*, application/gzip"
/> />
<button <button className="btn btn-sm btn-primary" onClick={handleFileOpen}>
className="btn btn-sm btn-primary"
onClick={() => inputRef.click()}
>
{uploadContent ? 'Upload a Different File' : 'Upload a File'} {uploadContent ? 'Upload a Different File' : 'Upload a File'}
</button> </button>
{uploadContent {uploadContent
@ -55,8 +51,7 @@ const WriteDataBody = ({
uploadContent={uploadContent} uploadContent={uploadContent}
/> />
</div> </div>
) )
}
const {func, string, bool} = PropTypes const {func, string, bool} = PropTypes
@ -69,6 +64,8 @@ WriteDataBody.propTypes = {
uploadContent: string, uploadContent: string,
fileName: string, fileName: string,
isManual: bool, isManual: bool,
fileInput: func.isRequired,
handleFileOpen: func.isRequired,
} }
export default WriteDataBody export default WriteDataBody

View File

@ -27,6 +27,7 @@ class WriteDataForm extends Component {
this.handleEdit = ::this.handleEdit this.handleEdit = ::this.handleEdit
this.handleFile = ::this.handleFile this.handleFile = ::this.handleFile
this.toggleWriteView = ::this.toggleWriteView this.toggleWriteView = ::this.toggleWriteView
this.handleFileOpen = ::this.handleFileOpen
} }
toggleWriteView(isManual) { toggleWriteView(isManual) {
@ -139,10 +140,12 @@ class WriteDataForm extends Component {
/> />
<WriteDataBody <WriteDataBody
{...this.state} {...this.state}
fileInput={el => this.fileInput = el}
handleEdit={this.handleEdit} handleEdit={this.handleEdit}
handleFile={this.handleFile} handleFile={this.handleFile}
handleKeyUp={this.handleKeyUp} handleKeyUp={this.handleKeyUp}
handleSubmit={this.handleSubmit} handleSubmit={this.handleSubmit}
handleFileOpen={this.handleFileOpen}
/> />
</div> </div>
<div className="write-data-form--drag-here"> <div className="write-data-form--drag-here">