14
14
* limitations under the License.
15
15
*/
16
16
17
- import { ChangeEvent } from 'react'
17
+ import { ChangeEvent , useMemo } from 'react'
18
18
19
- import { ReactComponent as ICUploadArrowAnimated } from '@Icons/ic-upload-arrow-animated.svg'
20
- import { ReactComponent as ICFileText } from '@Icons/ic-file-text.svg'
21
19
import { ReactComponent as ICCross } from '@Icons/ic-cross.svg'
20
+ import { ReactComponent as ICFileText } from '@Icons/ic-file-text.svg'
21
+ import { ReactComponent as ICUploadArrowAnimated } from '@Icons/ic-upload-arrow-animated.svg'
22
22
import { Tooltip } from '@Common/Tooltip'
23
-
24
23
import { ComponentSizeType } from '@Shared/constants'
24
+ import { getUniqueId } from '@Shared/Helpers'
25
25
26
26
import { Button , ButtonStyleType , ButtonVariantType } from '../Button'
27
27
import { FileUploadProps } from './types'
@@ -36,6 +36,8 @@ export const FileUpload = ({
36
36
fileTypes = [ ] ,
37
37
onUpload,
38
38
} : FileUploadProps ) => {
39
+ const id = useMemo ( ( ) => `fileInput-${ getUniqueId ( ) } ` , [ ] )
40
+
39
41
// METHODS
40
42
const handleFileChange = ( event : ChangeEvent < HTMLInputElement > ) => {
41
43
if ( event . target . files ) {
@@ -88,11 +90,11 @@ export const FileUpload = ({
88
90
) : (
89
91
< div className = "dc__position-rel flex" >
90
92
{ /* eslint-disable-next-line jsx-a11y/label-has-associated-control */ }
91
- < label htmlFor = "fileInput" className = "m-0 fw-4 cb-5 fs-13 lh-20 flex-grow-1 cursor" >
93
+ < label htmlFor = { id } className = "m-0 fw-4 cb-5 fs-13 lh-20 flex-grow-1 cursor" >
92
94
{ label || 'Upload file…' }
93
95
</ label >
94
96
< input
95
- id = "fileInput"
97
+ id = { id }
96
98
type = "file"
97
99
className = "dc__visibility-hidden dc__position-abs dc__top-0 dc__right-0 dc__bottom-0 dc__left-0"
98
100
onChange = { handleFileChange }
0 commit comments