Spaces:
Running
Running
akmhatey-ai commited on
Commit ·
60b6c5d
1
Parent(s): 2ea6ebc
fix: forward textarea ref for auto resize
Browse files
frontend/src/components/chat/ChatPanel.tsx
CHANGED
|
@@ -44,7 +44,12 @@ export default function ChatPanel({ activeDoc, onCitationClick }: Props) {
|
|
| 44 |
if (!textarea) return;
|
| 45 |
|
| 46 |
textarea.style.height = "auto";
|
| 47 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
const nextHeight = Math.min(textarea.scrollHeight, maxHeight);
|
| 49 |
textarea.style.height = `${nextHeight}px`;
|
| 50 |
textarea.style.overflowY =
|
|
|
|
| 44 |
if (!textarea) return;
|
| 45 |
|
| 46 |
textarea.style.height = "auto";
|
| 47 |
+
const computedMaxHeight = Number.parseFloat(
|
| 48 |
+
window.getComputedStyle(textarea).maxHeight
|
| 49 |
+
);
|
| 50 |
+
const maxHeight = Number.isFinite(computedMaxHeight)
|
| 51 |
+
? computedMaxHeight
|
| 52 |
+
: textarea.scrollHeight;
|
| 53 |
const nextHeight = Math.min(textarea.scrollHeight, maxHeight);
|
| 54 |
textarea.style.height = `${nextHeight}px`;
|
| 55 |
textarea.style.overflowY =
|
frontend/src/components/ui/textarea.tsx
CHANGED
|
@@ -2,9 +2,13 @@ import * as React from "react"
|
|
| 2 |
|
| 3 |
import { cn } from "@/lib/utils"
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
return (
|
| 7 |
<textarea
|
|
|
|
| 8 |
data-slot="textarea"
|
| 9 |
className={cn(
|
| 10 |
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
@@ -13,6 +17,8 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
| 13 |
{...props}
|
| 14 |
/>
|
| 15 |
)
|
| 16 |
-
}
|
|
|
|
|
|
|
| 17 |
|
| 18 |
export { Textarea }
|
|
|
|
| 2 |
|
| 3 |
import { cn } from "@/lib/utils"
|
| 4 |
|
| 5 |
+
const Textarea = React.forwardRef<
|
| 6 |
+
HTMLTextAreaElement,
|
| 7 |
+
React.ComponentProps<"textarea">
|
| 8 |
+
>(({ className, ...props }, ref) => {
|
| 9 |
return (
|
| 10 |
<textarea
|
| 11 |
+
ref={ref}
|
| 12 |
data-slot="textarea"
|
| 13 |
className={cn(
|
| 14 |
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
|
|
| 17 |
{...props}
|
| 18 |
/>
|
| 19 |
)
|
| 20 |
+
})
|
| 21 |
+
|
| 22 |
+
Textarea.displayName = "Textarea"
|
| 23 |
|
| 24 |
export { Textarea }
|