Add auto-focus to input field when sidebar opens

This commit is contained in:
tusharmagar 2026-01-16 11:22:17 +05:30
parent da4acdf31e
commit 2cf3f9cc95

View file

@ -1,4 +1,4 @@
import { useCallback, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { ArrowUp, PanelRightClose, Plus } from 'lucide-react'
import type { LanguageModelUsage, ToolUIPart } from 'ai'
import { Button } from '@/components/ui/button'
@ -152,6 +152,11 @@ export function ChatSidebar({
document.addEventListener('mouseup', handleMouseUp)
}, [width])
// Auto-focus input when sidebar opens
useEffect(() => {
inputRef.current?.focus()
}, [])
const hasConversation = conversation.length > 0 || currentAssistantMessage || currentReasoning
const canSubmit = Boolean(message.trim()) && !isProcessing