-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathUploadInput.js
48 lines (43 loc) · 1.12 KB
/
UploadInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @flow
* @file Input element for folder/file upload
* @author Box
*/
import * as React from 'react';
type Props = {
handleChange: Function,
inputLabel?: React.Node,
inputLabelClass?: string,
isFolderUpload?: boolean,
isMultiple?: boolean,
};
const UploadInput = ({
handleChange,
inputLabel,
inputLabelClass = '',
isFolderUpload = false,
isMultiple = true,
}: Props) => {
const inputRef = React.useRef(null);
const onKeyDown = e => {
if (e.key === 'Enter' || e.key === ' ') {
if (inputRef.current) {
inputRef.current.click();
}
}
};
return inputLabel ? (
<label className={inputLabelClass} onKeyDown={onKeyDown} tabIndex={0}>
{inputLabel}
<input
ref={inputRef}
directory={isFolderUpload ? '' : undefined}
multiple={isMultiple}
onChange={handleChange}
type="file"
webkitdirectory={isFolderUpload ? '' : undefined}
/>
</label>
) : null;
};
export default UploadInput;