Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: textarea show fit height of content and set a max height
  • Loading branch information
jaaydenh committed May 20, 2025
commit 57060bc4c0f5a8a6dc9969b2d773148c148afa88
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,30 @@ const DebouncedParameterField: FC<DebouncedParameterFieldProps> = ({
}, [debouncedLocalValue, onChangeEvent]);

switch (parameter.form_type) {
case "textarea":
case "textarea": {
const textareaRef = useRef<HTMLTextAreaElement>(null);

const resizeTextarea = useEffectEvent(() => {
if (textareaRef.current) {
const textarea = textareaRef.current;
textarea.style.height = "auto";
textarea.style.height = `${textarea.scrollHeight}px`;
}
});

useEffect(() => {
resizeTextarea();
}, [resizeTextarea]);

return (
<Textarea
ref={textareaRef}
id={id}
className="max-w-2xl"
className="overflow-y-auto max-h-[500px]"
value={localValue}
onChange={(e) => {
const target = e.currentTarget;
target.style.height = "auto";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a static style and should be turned into a tailwind class as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I test this, If I don't set height to auto in the onchange, the textarea height does not get updated correctly when the users adds and removes lines from the textarea

target.style.maxHeight = "700px";
target.style.height = `${target.scrollHeight}px`;

setLocalValue(e.target.value);
Expand All @@ -260,6 +274,7 @@ const DebouncedParameterField: FC<DebouncedParameterFieldProps> = ({
required={parameter.required}
/>
);
}

case "input": {
const inputType = parameter.type === "number" ? "number" : "text";
Expand Down
Loading