|
1 | | -import React from "react"; |
| 1 | +import React, { useEffect, useRef } from "react"; |
2 | 2 | import { AztecMark, Icons } from "./Icons"; |
3 | 3 | import Hero from "./Hero"; |
4 | 4 | import { UserBubble, AssistantBody } from "./Message"; |
@@ -58,6 +58,16 @@ export default function Panel({ |
58 | 58 | ? "Share failed" |
59 | 59 | : "Share"; |
60 | 60 |
|
| 61 | + const taRef = useRef(null); |
| 62 | + // Auto-grow the textarea to fit its content. The inline `max-height` |
| 63 | + // caps it at 10 lines; past that the textarea scrolls instead. |
| 64 | + useEffect(() => { |
| 65 | + const ta = taRef.current; |
| 66 | + if (!ta) return; |
| 67 | + ta.style.height = "auto"; |
| 68 | + ta.style.height = ta.scrollHeight + "px"; |
| 69 | + }, [input]); |
| 70 | + |
61 | 71 | return ( |
62 | 72 | <div |
63 | 73 | style={{ |
@@ -362,21 +372,36 @@ export default function Panel({ |
362 | 372 | border: `1px solid ${isInk ? "rgba(242,238,225,0.25)" : "var(--azw-ink-tint-1)"}`, |
363 | 373 | }} |
364 | 374 | > |
365 | | - <input |
| 375 | + <textarea |
| 376 | + ref={taRef} |
366 | 377 | value={input} |
367 | 378 | onChange={(e) => onInputChange(e.target.value)} |
| 379 | + onKeyDown={(e) => { |
| 380 | + if (e.key === "Enter" && !e.shiftKey) { |
| 381 | + e.preventDefault(); |
| 382 | + onSend(); |
| 383 | + } |
| 384 | + }} |
368 | 385 | placeholder="Ask about Aztec —" |
369 | 386 | disabled={streaming} |
| 387 | + rows={1} |
370 | 388 | style={{ |
371 | 389 | flex: 1, |
| 390 | + minWidth: 0, |
372 | 391 | padding: "11px 12px", |
373 | 392 | background: "transparent", |
374 | 393 | border: "none", |
375 | 394 | outline: "none", |
| 395 | + resize: "none", |
376 | 396 | color: panelFg, |
377 | 397 | fontFamily: "var(--azw-font-sans)", |
378 | 398 | fontSize: 13.5, |
| 399 | + lineHeight: 1.5, |
379 | 400 | letterSpacing: "-0.01em", |
| 401 | + boxSizing: "border-box", |
| 402 | + maxHeight: "calc(10 * 1.5em + 22px)", |
| 403 | + overflowY: "auto", |
| 404 | + overflowWrap: "anywhere", |
380 | 405 | }} |
381 | 406 | /> |
382 | 407 | <button |
|
0 commit comments