Skip to content

Commit eae8e36

Browse files
FilePicker multi upload update to open file explorer
1 parent 9483596 commit eae8e36

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

src/controls/filePicker/MultipleUploadFilePickerTab/MultipleUploadFilePickerTab.tsx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export default class MultipleUploadFilePicketTab extends React.Component<IMultip
2323
};
2424
}
2525

26-
private displayFileNames = (filesResult) =>{
27-
const result = [];
28-
for (var i = 0; i < filesResult.length; i++) {
29-
result.push(<div key={i.toString()} className={styles.localTabFilename}>{filesResult[i].name}</div>);
26+
private displayFileNames = (filesResult) => {
27+
const result = [];
28+
for (var i = 0; i < filesResult.length; i++) {
29+
result.push(<div key={i.toString()} className={styles.localTabFilename}>{filesResult[i].name}</div>);
30+
}
31+
return result;
3032
}
31-
return result;
32-
}
3333

3434
public render(): React.ReactElement<IMultipleUploadFilePickerTabProps> {
3535
const { filesResult } = this.state;
@@ -38,15 +38,24 @@ export default class MultipleUploadFilePicketTab extends React.Component<IMultip
3838
return (
3939
<div className={styles.tabContainer}>
4040
<div className={styles.tabHeaderContainer}>
41-
<h2 className={styles.tabHeader}>{strings.UploadLinkLabel+" "+strings.OneDriveRootFolderName}</h2>
41+
<h2 className={styles.tabHeader}>{strings.UploadLinkLabel + " " + strings.OneDriveRootFolderName}</h2>
4242
</div>
4343
<div className={css(styles.tab, styles.tabOffset)}>
44+
4445
<DragDropFiles
4546
iconName="BulkUpload"
46-
onDrop={this._handleFileUpload}
47+
onDrop={this._handleFileUploadDragDrop}
4748
>
4849
<div className={styles.localTabDragDropFile}>
49-
{strings.UploadLinkLabel+" "+strings.OneDriveRootFolderName}
50+
<input
51+
className={styles.localTabInput}
52+
type="file" id="fileInput"
53+
accept={acceptedFilesExtensions} multiple={true} onChange={(event: React.ChangeEvent<HTMLInputElement>) => this._handleFileUploadExplorer(event)}
54+
/>
55+
<label className={styles.localTabLabel} htmlFor="fileInput">
56+
{strings.UploadLinkLabel + " " + strings.OneDriveRootFolderName}
57+
</label>
58+
5059
</div>
5160
</DragDropFiles>
5261

@@ -60,7 +69,7 @@ export default class MultipleUploadFilePicketTab extends React.Component<IMultip
6069
<div className={styles.actionButtons}>
6170
<PrimaryButton
6271
disabled={!filesResult}
63-
onClick={() => this._handleSave()} className={styles.actionButton}>{strings.ListItemAttachmentslPlaceHolderButtonLabel+" "+strings.OneDriveRootFolderName}</PrimaryButton>
72+
onClick={() => this._handleSave()} className={styles.actionButton}>{strings.ListItemAttachmentslPlaceHolderButtonLabel + " " + strings.OneDriveRootFolderName}</PrimaryButton>
6473
<DefaultButton onClick={() => this._handleClose()} className={styles.actionButton}>{strings.CancelButtonLabel}</DefaultButton>
6574
</div>
6675
</div>
@@ -69,24 +78,38 @@ export default class MultipleUploadFilePicketTab extends React.Component<IMultip
6978
}
7079

7180
/**
72-
* Gets called when files are uploaded
81+
* Gets called when files are uploaded via drag and drop
7382
*/
74-
private _handleFileUpload = (files) => {
83+
private _handleFileUploadDragDrop = (files) => {
84+
7585
if (files.length < 1) {
7686
return;
77-
}else{
87+
} else {
7888
this.setState({
7989
filesResult: files
8090
});
8191
}
8292
}
8393

94+
/**
95+
* Gets called when files are uploaded via file explorer
96+
*/
97+
private _handleFileUploadExplorer = (event: React.ChangeEvent<HTMLInputElement>) => {
98+
if (!event || event.target.files.length < 1) {
99+
return;
100+
} else {
101+
this.setState({
102+
filesResult: event.target.files
103+
});
104+
}
105+
106+
}
107+
84108
/**
85109
* Saves base64 encoded image back to property pane file picker
86110
*/
87111
private _handleSave = () => {
88-
if(this.state.filesResult)
89-
{
112+
if (this.state.filesResult) {
90113
const files: File[] = this.state.filesResult;
91114
for (var i = 0; i < files.length; i++) {
92115
const filePickerResult: IFilePickerResult = {

0 commit comments

Comments
 (0)