Skip to content

Commit 3a6d5f5

Browse files
authored
fix: update textarea to fit content height and set a max height (#17946)
1 parent 36d938f commit 3a6d5f5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,30 @@ const DebouncedParameterField: FC<DebouncedParameterFieldProps> = ({
239239

240240
prevDebouncedValueRef.current = debouncedLocalValue;
241241
}, [debouncedLocalValue, onChangeEvent]);
242+
const textareaRef = useRef<HTMLTextAreaElement>(null);
243+
244+
const resizeTextarea = useEffectEvent(() => {
245+
if (textareaRef.current) {
246+
const textarea = textareaRef.current;
247+
textarea.style.height = `${textarea.scrollHeight}px`;
248+
}
249+
});
250+
251+
useEffect(() => {
252+
resizeTextarea();
253+
}, [resizeTextarea]);
242254

243255
switch (parameter.form_type) {
244-
case "textarea":
256+
case "textarea": {
245257
return (
246258
<Textarea
259+
ref={textareaRef}
247260
id={id}
248-
className="max-w-2xl"
261+
className="overflow-y-auto max-h-[500px]"
249262
value={localValue}
250263
onChange={(e) => {
251264
const target = e.currentTarget;
252265
target.style.height = "auto";
253-
target.style.maxHeight = "700px";
254266
target.style.height = `${target.scrollHeight}px`;
255267

256268
setLocalValue(e.target.value);
@@ -260,6 +272,7 @@ const DebouncedParameterField: FC<DebouncedParameterFieldProps> = ({
260272
required={parameter.required}
261273
/>
262274
);
275+
}
263276

264277
case "input": {
265278
const inputType = parameter.type === "number" ? "number" : "text";

0 commit comments

Comments
 (0)