Skip to content
Merged
Changes from all commits
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
41 changes: 25 additions & 16 deletions frontend/app/view/waveai/waveai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,24 +572,33 @@ const ChatInput = forwardRef<HTMLTextAreaElement, ChatInputProps>(
model.textAreaRef = textAreaRef;
}, []);

const adjustTextAreaHeight = () => {
if (textAreaRef.current == null) {
return;
}
// Adjust the height of the textarea to fit the text
const textAreaMaxLines = 100;
const textAreaLineHeight = termFontSize * 1.5;
const textAreaMinHeight = textAreaLineHeight;
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;

textAreaRef.current.style.height = "1px";
const scrollHeight = textAreaRef.current.scrollHeight;
const newHeight = Math.min(Math.max(scrollHeight, textAreaMinHeight), textAreaMaxHeight);
textAreaRef.current.style.height = newHeight + "px";
};
const adjustTextAreaHeight = useCallback(
(value: string) => {
if (textAreaRef.current == null) {
return;
}

// Adjust the height of the textarea to fit the text
const textAreaMaxLines = 5;
const textAreaLineHeight = termFontSize * 1.5;
const textAreaMinHeight = textAreaLineHeight;
const textAreaMaxHeight = textAreaLineHeight * textAreaMaxLines;

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 (
Expand Down