Skip to content

Commit

Permalink
added inputId attribute: input element ID (#3)
Browse files Browse the repository at this point in the history
add an ID to the input element
  • Loading branch information
Huuums authored and nzambello committed Jun 7, 2018
1 parent ccc366f commit 93fab29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class App extends Component {
label="Select CSV with secret Death Star statistics"
onFileLoaded={this.handleForce}
onError={this.handleDarkSideForce}
inputId="ObiWan"
/>
)
}
Expand All @@ -58,6 +59,7 @@ ReactDOM.render(<App />, document.getElementById('root'))
| label | string, element | | If present, it will be rendered in a `<label>` to describe input aim. |
| onFileLoaded | function | | (**_required_**) The function to be called passing loaded results. |
| onError | function | | Error handling function. |
| inputId | string | | An id to be applied to the `<input>` element. |

### Results

Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { string, func, element, oneOfType } from 'prop-types';
const PapaParse = require('papaparse/papaparse.min.js');

const CSVReader = ({ cssClass = 'csv-reader-input', label, onFileLoaded, onError }) => {
const CSVReader = ({ cssClass = 'csv-reader-input', label, onFileLoaded, onError, inputId = null }) => {
let fileContent = undefined;

const handleChangeFile = e => {
Expand All @@ -22,7 +22,7 @@ const CSVReader = ({ cssClass = 'csv-reader-input', label, onFileLoaded, onError
return (
<div className={cssClass}>
{label && <label>{label}</label>}
<input className="csv-input" type="file" accept="text/csv" onChange={e => handleChangeFile(e)} />
<input className="csv-input" type="file" id={inputId} accept="text/csv" onChange={e => handleChangeFile(e)} />
</div>
);
};
Expand All @@ -31,7 +31,8 @@ CSVReader.propTypes = {
cssClass: string,
label: oneOfType([string, element]),
onFileLoaded: func,
onError: func
onError: func,
inputId: string
};

export default CSVReader;
export default CSVReader;

3 comments on commit 93fab29

@ioannagian
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nzambello Thank you for this component!
Could you please make a new release including this commit?

@nzambello
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ioannagian yes, of course.
This evening you'll have a new release 👍

@nzambello
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ioannagian released v0.3.1 🍻

Please sign in to comment.