Skip to content

Open source CapCut alternative.

TypeScript

feat(site): Cut chat input grows to fit typed content

David Leb63db5dbd754
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index c0733a83..003c330b 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -582,8 +582,9 @@ function ChatSession({
className="px-2.5 pt-2.5"
/>
<MentionTextarea
- className="ai-input max-h-40 min-h-[38px] w-full resize-none bg-transparent px-3 pt-2 text-[12.5px] leading-relaxed outline-none placeholder:text-muted-foreground/70"
+ className="ai-input max-h-40 min-h-[38px] w-full resize-none overflow-y-auto bg-transparent px-3 pt-2 text-[12.5px] leading-relaxed outline-none placeholder:text-muted-foreground/70"
rows={2}
+ autoGrow
placeholder="Ask about your video, or tell me what to change… @ references media"
value={input}
onChange={setInput}
diff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsx
index f4a9d5c6..9b5d5360 100644
--- a/site/src/cut/components/AssetRefs.tsx
+++ b/site/src/cut/components/AssetRefs.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useMemo, useRef, useState } from "react";
+import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { Check, Copy, FileText, X } from "lucide-react";
import {
highlightMentions,
@@ -358,6 +358,7 @@ export function MentionTextarea({
placeholder,
className,
rows,
+ autoGrow = false,
}: {
value: string;
onChange: (v: string) => void;
@@ -369,6 +370,10 @@ export function MentionTextarea({
placeholder?: string;
className?: string;
rows?: number;
+ /** Grow the textarea to fit its content as the user types (capped by the
+ caller's `max-h-*`). Leave off when the caller wants a fixed or
+ manually resizable box. */
+ autoGrow?: boolean;
}) {
const taRef = useRef<HTMLTextAreaElement>(null);
const backdropRef = useRef<HTMLDivElement>(null);
@@ -408,6 +413,16 @@ export function MentionTextarea({
});
};
+ // Auto-grow: reset to natural height, then match the content. The caller's
+ // `max-h-*` caps it and the textarea scrolls internally past that point.
+ useLayoutEffect(() => {
+ if (!autoGrow) return;
+ const el = taRef.current;
+ if (!el) return;
+ el.style.height = "auto";
+ el.style.height = `${el.scrollHeight}px`;
+ }, [autoGrow, value]);
+
return (
<div className="relative min-w-0">
{open && (