-
Notifications
You must be signed in to change notification settings - Fork 894
fix: update textarea to fit content height and set a max height #17946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -260,6 +274,7 @@ const DebouncedParameterField: FC<DebouncedParameterFieldProps> = ({ | |
required={parameter.required} | ||
/> | ||
); | ||
} | ||
|
||
case "input": { | ||
const inputType = parameter.type === "number" ? "number" : "text"; | ||
|
Uh oh!
There was an error while loading. Please reload this page.