diff --git a/components/Settings/Key.tsx b/components/Settings/Key.tsx index cec7797..c52d787 100644 --- a/components/Settings/Key.tsx +++ b/components/Settings/Key.tsx @@ -1,6 +1,6 @@ import { IconCheck, IconKey, IconX } from '@tabler/icons-react'; import { useTranslation } from 'next-i18next'; -import { FC, KeyboardEvent, useState } from 'react'; +import { FC, KeyboardEvent, useEffect, useRef, useState } from 'react'; import { SidebarButton } from '../Sidebar/SidebarButton'; interface Props { @@ -12,6 +12,7 @@ export const Key: FC = ({ apiKey, onApiKeyChange }) => { const { t } = useTranslation('sidebar'); const [isChanging, setIsChanging] = useState(false); const [newKey, setNewKey] = useState(apiKey); + const inputRef = useRef(null); const handleEnterDown = (e: KeyboardEvent) => { if (e.key === 'Enter') { @@ -24,12 +25,19 @@ export const Key: FC = ({ apiKey, onApiKeyChange }) => { onApiKeyChange(newKey.trim()); setIsChanging(false); }; + + useEffect(() => { + if (isChanging) { + inputRef.current?.focus(); + } + }, [isChanging]); return isChanging ? (