Skip to content

Commit

Permalink
Renamed FileUpload onUpload prop to onSelect.
Browse files Browse the repository at this point in the history
Added value prop to FileUpload.
  • Loading branch information
sjohnsonaz committed Jun 9, 2020
1 parent 10c37fd commit 8d48275
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/scripts/components/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as React from 'react';
export interface IFileUploadProps {
id?: string;
className?: string;
onUpload: (files: FileList) => any;
onSelect: (files: FileList) => Promise<any>;
value?: string;
text?: string;
}

Expand All @@ -23,7 +24,7 @@ export default class FileUpload extends React.Component<IFileUploadProps, IFileU
this.setState({
uploading: true
}, async () => {
await this.props.onUpload(files);
await this.props.onSelect(files);
this.setState({
uploading: false
});
Expand All @@ -38,7 +39,7 @@ export default class FileUpload extends React.Component<IFileUploadProps, IFileU
event.stopPropagation();
}

upload = () => {
select = () => {
let fileInput = this.fileInput.current;
let files = fileInput.files;
if (files && files.length) {
Expand Down Expand Up @@ -76,7 +77,8 @@ export default class FileUpload extends React.Component<IFileUploadProps, IFileU
let {
id,
className,
text
text,
value
} = this.props;

let classNames = className ? [className] : [];
Expand All @@ -97,7 +99,8 @@ export default class FileUpload extends React.Component<IFileUploadProps, IFileU
>
<input
type="file"
onChange={this.upload}
onChange={this.select}
value={value}
onClick={this.clickStop}
multiple
ref={this.fileInput}
Expand Down
5 changes: 3 additions & 2 deletions src/tests/demo/scripts/views/file-upload/FileUploadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ export interface ITableViewProps {
}

export default class TableView extends React.Component<ITableViewProps, any> {
upload = async (files: FileList) => {
select = async (files: FileList) => {
console.log('files:', files);
return undefined;
}

render() {
return (
<Section
header="File Upload"
headerSpace
space
>
<FileUpload onUpload={this.upload} />
<FileUpload onSelect={this.select} />
</Section>
);
}
Expand Down

0 comments on commit 8d48275

Please sign in to comment.