@@ -28,6 +28,7 @@ import {
2828 useContext ,
2929 useEffect ,
3030 useId ,
31+ useRef ,
3132 useState ,
3233} from "react" ;
3334import { getFormHelpers , nameValidator } from "utils/formUtils" ;
@@ -103,6 +104,7 @@ export const CreateWorkspacePageViewExperimental: FC<
103104 ) ;
104105 const [ showPresetParameters , setShowPresetParameters ] = useState ( false ) ;
105106 const id = useId ( ) ;
107+ const workspaceNameInputRef = useRef < HTMLInputElement > ( null ) ;
106108 const rerollSuggestedName = useCallback ( ( ) => {
107109 setSuggestedName ( ( ) => generateWorkspaceName ( ) ) ;
108110 } , [ ] ) ;
@@ -142,14 +144,10 @@ export const CreateWorkspacePageViewExperimental: FC<
142144
143145 useEffect ( ( ) => {
144146 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 ( ) ;
151149 }
152- } , [ form . submitCount , form . errors , id ] ) ;
150+ } , [ form . submitCount , form . errors ] ) ;
153151
154152 const [ presetOptions , setPresetOptions ] = useState ( [
155153 { label : "None" , value : "" } ,
@@ -342,6 +340,7 @@ export const CreateWorkspacePageViewExperimental: FC<
342340 < div className = "flex flex-col" >
343341 < Input
344342 id = { `${ id } -workspace-name` }
343+ ref = { workspaceNameInputRef }
345344 value = { form . values . name }
346345 onChange = { ( e ) => {
347346 form . setFieldValue ( "name" , e . target . value . trim ( ) ) ;
0 commit comments