1- import { useEffect , useState } from 'react' ;
1+ import { useEffect , useRef , useState } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { useRecoilValue } from 'recoil' ;
44
@@ -31,6 +31,7 @@ export function FileInput({
3131 const openAddCluster = useRecoilValue ( showAddClusterWizard ) ;
3232 const [ draggingOverCounter , setDraggingCounter ] = useState ( 0 ) ;
3333 const { t } = useTranslation ( ) ;
34+ const fileNameRef = useRef ( null ) ;
3435
3536 useEffect ( ( ) => {
3637 if ( ! openAdd && ! openAddCluster ) setFileNames ( [ ] ) ;
@@ -47,6 +48,12 @@ export function FileInput({
4748 if ( files . length ) {
4849 fileInputChanged ( files ) ;
4950 }
51+
52+ if ( fileNameRef . current ) {
53+ setTimeout ( ( ) => {
54+ fileNameRef . current ?. focus ( ) ;
55+ } , 50 ) ; // Timeout to ensure the focus is set after the DOM update
56+ }
5057 }
5158
5259 function drop ( e ) {
@@ -104,11 +111,12 @@ export function FileInput({
104111 { availableFormatsMessage && (
105112 < p className = "file-input__secondary" > { availableFormatsMessage } </ p >
106113 ) }
107- { ! ! fileNames . length && (
108- < p className = "file-input__secondary" >
109- { `${ fileNames . join ( ', ' ) } ${ t ( 'components.file-input.uploaded' ) } ` }
110- </ p >
111- ) }
114+
115+ < p className = "file-input__secondary" ref = { fileNameRef } tabIndex = { 1 } >
116+ { fileNames . length
117+ ? `${ fileNames . join ( ', ' ) } ${ t ( 'components.file-input.uploaded' ) } `
118+ : '' }
119+ </ p >
112120 </ div >
113121 </ label >
114122 ) ;
0 commit comments