diff --git a/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx b/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx index d5e5b00d5..c64c12a2c 100644 --- a/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx +++ b/apps/browser-extension/src/entrypoints/popup/components/FormInput.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { forwardRef } from 'react'; /** * Form input props. @@ -19,7 +19,7 @@ type FormInputProps = { /** * Form input component. */ -export const FormInput: React.FC = ({ +export const FormInput = forwardRef(({ id, label, value, @@ -30,7 +30,7 @@ export const FormInput: React.FC = ({ multiline = false, rows = 1, error -}) => { +}, ref) => { const [showPassword, setShowPassword] = React.useState(false); const inputClasses = `mt-1 block w-full rounded-md ${ @@ -55,6 +55,7 @@ export const FormInput: React.FC = ({ /> ) : ( = ({ )} ); -}; \ No newline at end of file +}); + +FormInput.displayName = 'FormInput'; \ No newline at end of file diff --git a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx index af1cb9ea2..580df3d7a 100644 --- a/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx +++ b/apps/browser-extension/src/entrypoints/popup/pages/CredentialAddEdit.tsx @@ -1,5 +1,5 @@ import { yupResolver } from '@hookform/resolvers/yup'; -import React, { useState, useEffect, useCallback } from 'react'; +import React, { useState, useEffect, useCallback, useRef } from 'react'; import { useForm } from 'react-hook-form'; import { useNavigate, useParams } from 'react-router-dom'; import * as Yup from 'yup'; @@ -64,6 +64,8 @@ const CredentialAddEdit: React.FC = () => { const { setHeaderButtons } = useHeaderButtons(); const { setIsInitialLoading } = useLoading(); + const serviceNameRef = useRef(null); + const { handleSubmit, setValue, watch, formState: { errors } } = useForm({ resolver: yupResolver(credentialSchema), defaultValues: { @@ -92,6 +94,11 @@ const CredentialAddEdit: React.FC = () => { */ useEffect(() => { if (!dbContext?.sqliteClient || !id) { + // On create mode, focus the service name field after a short delay to ensure the component is mounted. + setTimeout(() => { + serviceNameRef.current?.focus(); + }, 100); + return; } @@ -105,10 +112,10 @@ const CredentialAddEdit: React.FC = () => { Object.entries(result).forEach(([key, value]) => { setValue(key as keyof Credential, value); }); - // If credential has alias data, switch to manual mode - if (result.Alias?.FirstName || result.Alias?.LastName) { - setMode('manual'); - } + + setMode('manual'); + + // On create mode, focus the service name field after a short delay to ensure the component is mounted } else { console.error('Credential not found'); navigate('/credentials'); @@ -321,6 +328,7 @@ const CredentialAddEdit: React.FC = () => { setValue('ServiceName', value)} required