diff --git a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx index e77b934cb3..2786b17abf 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx @@ -80,7 +80,9 @@ export const AiAssistantChatWindowInput = ({ useEffect(() => { adjustTextareaHeight() - inputRef.current?.focus() + if (chatOpened) { + inputRef.current?.focus() + } }, [question]) const handleTouch = (e: React.TouchEvent) => { diff --git a/www/packages/docs-ui/src/providers/AiAssistant/index.tsx b/www/packages/docs-ui/src/providers/AiAssistant/index.tsx index df4841100e..e993c587cf 100644 --- a/www/packages/docs-ui/src/providers/AiAssistant/index.tsx +++ b/www/packages/docs-ui/src/providers/AiAssistant/index.tsx @@ -131,9 +131,11 @@ const AiAssistantInnerProvider = ({ useEffect(() => { setOnCompleteAction(() => { scrollToBottom() - inputRef.current?.focus({ - preventScroll: true, - }) + if (chatOpened) { + inputRef.current?.focus({ + preventScroll: true, + }) + } }) }, [scrollToBottom])