Files
openchamber/packages/ui/src/components/chat/questionTextareaSizing.ts
T
HearingSmileandBohdan Triapitsyn 3bbd42587e fix: stabilize question custom textarea resizing (#1614)
* fix: stabilize question custom textarea resizing

* fix: preserve custom question answer state

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-06-13 00:28:42 +03:00

19 lines
657 B
TypeScript

const QUESTION_TEXTAREA_LINE_HEIGHT = 20;
const QUESTION_TEXTAREA_MIN_LINES = 2;
const QUESTION_TEXTAREA_MAX_LINES = 10;
export const QUESTION_CUSTOM_TEXTAREA_MIN_HEIGHT = QUESTION_TEXTAREA_LINE_HEIGHT * QUESTION_TEXTAREA_MIN_LINES;
export function getQuestionCustomTextareaHeight({
scrollHeight,
currentHeight,
}: {
scrollHeight: number;
currentHeight: number | null | undefined;
}): number | null {
const maxHeight = QUESTION_TEXTAREA_LINE_HEIGHT * QUESTION_TEXTAREA_MAX_LINES;
const nextHeight = Math.min(Math.max(scrollHeight, QUESTION_CUSTOM_TEXTAREA_MIN_HEIGHT), maxHeight);
return currentHeight === nextHeight ? null : nextHeight;
}