diff --git a/autogpt_platform/frontend/src/components/contextual/Chat/components/ChatInput/useVoiceRecording.ts b/autogpt_platform/frontend/src/components/contextual/Chat/components/ChatInput/useVoiceRecording.ts index 56d345e234..4de74ef2e9 100644 --- a/autogpt_platform/frontend/src/components/contextual/Chat/components/ChatInput/useVoiceRecording.ts +++ b/autogpt_platform/frontend/src/components/contextual/Chat/components/ChatInput/useVoiceRecording.ts @@ -103,13 +103,6 @@ export function useVoiceRecording({ console.error("Transcription error:", err); } finally { setIsTranscribing(false); - // Refocus the input after transcription so user can continue typing or send - if (inputId) { - const inputElement = document.getElementById(inputId); - if (inputElement) { - inputElement.focus(); - } - } } }, [handleTranscription, inputId], @@ -210,6 +203,15 @@ export function useVoiceRecording({ } }, [error, toast]); + useEffect(() => { + if (!isTranscribing && inputId) { + const inputElement = document.getElementById(inputId); + if (inputElement) { + inputElement.focus(); + } + } + }, [isTranscribing, inputId]); + const handleKeyDown = useCallback( (event: KeyboardEvent) => { if (event.key === " " && !value.trim() && !isTranscribing) {