diff --git a/src/components/ui/textarea.tsx b/src/components/ui/textarea.tsx index 969f7eac..c4b1c870 100644 --- a/src/components/ui/textarea.tsx +++ b/src/components/ui/textarea.tsx @@ -3,15 +3,56 @@ import * as React from "react"; import { cn } from "@/lib/utils"; const Textarea = React.forwardRef>( - ({ className, ...props }, ref) => { + ({ className, value, ...props }, ref) => { + const textareaRef = React.useRef(null); + + const adjustHeight = React.useCallback(() => { + const textarea = textareaRef.current; + if (textarea) { + textarea.style.height = "auto"; + const newHeight = Math.min(textarea.scrollHeight, 300); + textarea.style.height = `${newHeight}px`; + } + }, []); + + // Watch for value changes to adjust height + React.useLayoutEffect(() => { + adjustHeight(); + }, [value, adjustHeight]); + + React.useEffect(() => { + adjustHeight(); + window.addEventListener("resize", adjustHeight); + return () => window.removeEventListener("resize", adjustHeight); + }, [adjustHeight]); + + const combinedRef = (node: HTMLTextAreaElement) => { + textareaRef.current = node; + if (typeof ref === "function") { + ref(node); + } else if (ref) { + ref.current = node; + } + }; + return (