@@ -255,17 +255,15 @@ export interface TableUploadDialogProps {
255255}
256256
257257export const TableUploadDialog : React . FC < TableUploadDialogProps > = ( { buttonElement, disabled } ) => {
258-
259258 const dispatch = useDispatch < AppDispatch > ( ) ;
260-
261- let $uploadInputFile = React . createRef < HTMLInputElement > ( ) ;
262-
263- let handleFileUpload = ( event : React . FormEvent < HTMLElement > ) : void => {
264- const target : any = event . target ;
265- if ( target && target . files ) {
266- for ( let file of target . files ) {
267- //const file: File = target.files[0];
268- ( file as File ) . text ( ) . then ( ( text ) => {
259+ const inputRef = React . useRef < HTMLInputElement > ( null ) ;
260+
261+ let handleFileUpload = ( event : React . ChangeEvent < HTMLInputElement > ) : void => {
262+ const files = event . target . files ;
263+
264+ if ( files ) {
265+ for ( let file of files ) {
266+ file . text ( ) . then ( ( text ) => {
269267 let table = loadDataWrapper ( file . name , text , file . type ) ;
270268 if ( table ) {
271269 dispatch ( dfActions . addTable ( table ) ) ;
@@ -276,14 +274,30 @@ export const TableUploadDialog: React.FC<TableUploadDialogProps> = ({ buttonElem
276274 }
277275 } ;
278276
279- return < Button sx = { { fontSize : "inherit" } } variant = "text" color = "primary"
280- disabled = { disabled } >
281- < Input inputProps = { { accept : '.csv,.tsv,.json' , multiple : true } } id = "upload-data-file"
282- type = "file" sx = { { display : 'none' } } aria-hidden = { true }
283- ref = { $uploadInputFile } onChange = { handleFileUpload }
284- />
277+ return (
278+ < >
279+ < Input
280+ inputProps = { {
281+ accept : '.csv,.tsv,.json' ,
282+ multiple : true ,
283+ } }
284+ id = "upload-data-file"
285+ type = "file"
286+ sx = { { display : 'none' } }
287+ inputRef = { inputRef }
288+ onChange = { handleFileUpload }
289+ />
290+ < Button
291+ sx = { { fontSize : "inherit" } }
292+ variant = "text"
293+ color = "primary"
294+ disabled = { disabled }
295+ onClick = { ( ) => inputRef . current ?. click ( ) }
296+ >
285297 { buttonElement }
286- </ Button > ;
298+ </ Button >
299+ </ >
300+ ) ;
287301}
288302
289303
0 commit comments