Skip to content

Commit 8d8dbe3

Browse files
authored
Merge pull request #10 from riccjohn/fix/auto-focus-chat-input
Auto-focus chat input when re-enabled after response
2 parents 33baa57 + 9bcd02d commit 8d8dbe3

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

components/ChatInput.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useRef, useState } from "react"
3+
import { useEffect, useRef, useState } from "react"
44

55
type Props = {
66
onSubmit: (value: string) => void
@@ -11,6 +11,12 @@ export function ChatInput({ onSubmit, isDisabled = false }: Props) {
1111
const [value, setValue] = useState("")
1212
const textareaRef = useRef<HTMLTextAreaElement>(null)
1313

14+
useEffect(() => {
15+
if (!isDisabled) {
16+
textareaRef.current?.focus()
17+
}
18+
}, [isDisabled])
19+
1420
const handleSubmit = () => {
1521
const trimmed = value.trim()
1622
if (!trimmed || isDisabled) return

0 commit comments

Comments
 (0)