Skip to content

Commit

Permalink
style: fix message form auto height
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljaijai committed Dec 3, 2024
1 parent 506b4af commit eb06c50
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions client/components/customized-ui/form/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ const FormTextArea: React.FunctionComponent<IFormTextArea> = ({
const adjustHeight = () => {
const textarea = textareaRef.current
if (textarea) {
textarea.style.height = "auto"
textarea.style.height = `${textarea.scrollHeight}px`
if (textarea.value.trim() === "") {
textarea.style.height = `${minRows * 24}px` // Assuming 24px line height
} else {
textarea.style.height = "auto"
textarea.style.height = `${textarea.scrollHeight}px`
}
}
}

useEffect(() => {
adjustHeight()
}, [])
}, [textareaRef.current?.value])

return (
<FormField
Expand All @@ -66,7 +70,6 @@ const FormTextArea: React.FunctionComponent<IFormTextArea> = ({
rows={minRows}
onChange={(e) => {
field.onChange(e)
adjustHeight()
}}
style={{ resize: "none" }}
/>
Expand Down

0 comments on commit eb06c50

Please sign in to comment.