Spaces:
Running
Running
akmhatey-ai commited on
Commit ·
2ea6ebc
1
Parent(s): c0a7e8e
fix: auto-resize chat textarea
Browse files
frontend/src/components/chat/ChatPanel.tsx
CHANGED
|
@@ -35,9 +35,22 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 35 |
const [messages, setMessages] = useState<ChatMsg[]>([]);
|
| 36 |
const [input, setInput] = useState("");
|
| 37 |
const [streaming, setStreaming] = useState(false);
|
|
|
|
| 38 |
const bottomRef = useRef<HTMLDivElement>(null);
|
| 39 |
const prevDocId = useRef<string | null>(null);
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
// Auto-scroll to bottom whenever messages change
|
| 42 |
useEffect(() => {
|
| 43 |
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
@@ -205,6 +218,7 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 205 |
<div className="border-t border-border/50 p-4 bg-card/30 backdrop-blur-sm">
|
| 206 |
<div className="max-w-3xl mx-auto flex gap-2 items-end">
|
| 207 |
<Textarea
|
|
|
|
| 208 |
id="chat-input"
|
| 209 |
value={input}
|
| 210 |
onChange={(e) => setInput(e.target.value)}
|
|
|
|
| 35 |
const [messages, setMessages] = useState<ChatMsg[]>([]);
|
| 36 |
const [input, setInput] = useState("");
|
| 37 |
const [streaming, setStreaming] = useState(false);
|
| 38 |
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
| 39 |
const bottomRef = useRef<HTMLDivElement>(null);
|
| 40 |
const prevDocId = useRef<string | null>(null);
|
| 41 |
|
| 42 |
+
useEffect(() => {
|
| 43 |
+
const textarea = textareaRef.current;
|
| 44 |
+
if (!textarea) return;
|
| 45 |
+
|
| 46 |
+
textarea.style.height = "auto";
|
| 47 |
+
const maxHeight = 128;
|
| 48 |
+
const nextHeight = Math.min(textarea.scrollHeight, maxHeight);
|
| 49 |
+
textarea.style.height = `${nextHeight}px`;
|
| 50 |
+
textarea.style.overflowY =
|
| 51 |
+
textarea.scrollHeight > maxHeight ? "auto" : "hidden";
|
| 52 |
+
}, [input]);
|
| 53 |
+
|
| 54 |
// Auto-scroll to bottom whenever messages change
|
| 55 |
useEffect(() => {
|
| 56 |
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
|
|
| 218 |
<div className="border-t border-border/50 p-4 bg-card/30 backdrop-blur-sm">
|
| 219 |
<div className="max-w-3xl mx-auto flex gap-2 items-end">
|
| 220 |
<Textarea
|
| 221 |
+
ref={textareaRef}
|
| 222 |
id="chat-input"
|
| 223 |
value={input}
|
| 224 |
onChange={(e) => setInput(e.target.value)}
|