Fix issue where WaveAI text area would resize on launch (#1397)

This commit is contained in:
Evan Simkowitz 2024-12-05 17:06:52 -05:00 committed by GitHub
parent 8ec3c3f330
commit cb50023d79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -572,24 +572,33 @@ const ChatInput = forwardRef<HTMLTextAreaElement, ChatInputProps>(
model.textAreaRef = textAreaRef;
}, []);
const adjustTextAreaHeight = () => {
const adjustTextAreaHeight = useCallback(
(value: string) => {
if (textAreaRef.current == null) {
return;
}
// Adjust the height of the textarea to fit the text
const textAreaMaxLines = 100;
const textAreaMaxLines = 5;
const textAreaLineHeight = termFontSize * 1.5;
const textAreaMinHeight = textAreaLineHeight;
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;
textAreaRef.current.style.height = "1px";
if (value === "") {
textAreaRef.current.style.height = `${textAreaLineHeight}px`;
return;
}
textAreaRef.current.style.height = `${textAreaLineHeight}px`;
const scrollHeight = textAreaRef.current.scrollHeight;
const newHeight = Math.min(Math.max(scrollHeight, textAreaMinHeight), textAreaMaxHeight);
textAreaRef.current.style.height = newHeight + "px";
};
},
[termFontSize]
);
useEffect(() => {
adjustTextAreaHeight();
adjustTextAreaHeight(value);
}, [value]);
return (