@@ -28,6 +28,7 @@ import {
28
28
useContext ,
29
29
useEffect ,
30
30
useId ,
31
+ useRef ,
31
32
useState ,
32
33
} from "react" ;
33
34
import { getFormHelpers , nameValidator } from "utils/formUtils" ;
@@ -103,6 +104,7 @@ export const CreateWorkspacePageViewExperimental: FC<
103
104
) ;
104
105
const [ showPresetParameters , setShowPresetParameters ] = useState ( false ) ;
105
106
const id = useId ( ) ;
107
+ const workspaceNameInputRef = useRef < HTMLInputElement > ( null ) ;
106
108
const rerollSuggestedName = useCallback ( ( ) => {
107
109
setSuggestedName ( ( ) => generateWorkspaceName ( ) ) ;
108
110
} , [ ] ) ;
@@ -142,14 +144,10 @@ export const CreateWorkspacePageViewExperimental: FC<
142
144
143
145
useEffect ( ( ) => {
144
146
if ( form . submitCount > 0 && form . errors ) {
145
- const fieldId = `${ id } -workspace-name` ;
146
- const el = document . getElementById ( fieldId ) ;
147
- if ( el ) {
148
- el . scrollIntoView ( { behavior : "smooth" , block : "center" } ) ;
149
- ( el as HTMLElement ) . focus ?.( ) ;
150
- }
147
+ workspaceNameInputRef . current ?. scrollIntoView ( { behavior : "smooth" , block : "center" } ) ;
148
+ workspaceNameInputRef . current ?. focus ( ) ;
151
149
}
152
- } , [ form . submitCount , form . errors , id ] ) ;
150
+ } , [ form . submitCount , form . errors ] ) ;
153
151
154
152
const [ presetOptions , setPresetOptions ] = useState ( [
155
153
{ label : "None" , value : "" } ,
@@ -342,6 +340,7 @@ export const CreateWorkspacePageViewExperimental: FC<
342
340
< div className = "flex flex-col" >
343
341
< Input
344
342
id = { `${ id } -workspace-name` }
343
+ ref = { workspaceNameInputRef }
345
344
value = { form . values . name }
346
345
onChange = { ( e ) => {
347
346
form . setFieldValue ( "name" , e . target . value . trim ( ) ) ;
0 commit comments