Skip to content

Commit a8aa4cd

Browse files
author
Victoria Ivanova
committed
fix textarea expanding
1 parent 1f26f5b commit a8aa4cd

File tree

1 file changed

+17
-29
lines changed
  • frontend/src/pages/Report/components/Bug

1 file changed

+17
-29
lines changed

frontend/src/pages/Report/components/Bug/Bug.tsx

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,23 @@ const Bug = ({ reportId, isNewReport, bugId }: BugProps) => {
7373
});
7474

7575
useEffect(() => {
76-
const root = document.documentElement;
77-
const rawCssVar = getComputedStyle(root).getPropertyValue("--spacing");
78-
const spacing = parseFloat(rawCssVar);
79-
// вычисляем значение паддинга у <textarea />
80-
// 3 -- потому что className p-3 у <textarea />
81-
const calculatedTextareaPaddingEm = spacing * 3;
82-
83-
if (receivedTextareaRef.current && expectedTextareaRef.current) {
84-
const fontSizePx = parseFloat(
85-
getComputedStyle(receivedTextareaRef.current).fontSize
86-
);
87-
const calculatedTextareaPaddingPx =
88-
calculatedTextareaPaddingEm * fontSizePx;
89-
const textareaReceiveScrollHeight = `${
90-
receivedTextareaRef.current.scrollHeight + calculatedTextareaPaddingPx
91-
}px`;
92-
const textareaExpectScrollHeight = `${
93-
expectedTextareaRef.current.scrollHeight + calculatedTextareaPaddingPx
94-
}px`;
95-
96-
if (textareaReceiveScrollHeight >= textareaExpectScrollHeight) {
97-
receivedTextareaRef.current.style.height = textareaReceiveScrollHeight;
98-
expectedTextareaRef.current.style.height = "100%";
99-
} else {
100-
expectedTextareaRef.current.style.height = textareaExpectScrollHeight;
101-
receivedTextareaRef.current.style.height = "100%";
102-
}
103-
}
104-
}, [receivedTextareaRef, expectedTextareaRef, newBugData, bug]);
76+
const receivedTextarea = receivedTextareaRef.current;
77+
const expectedTextarea = expectedTextareaRef.current;
78+
if (!receivedTextarea || !expectedTextarea) return;
79+
80+
receivedTextarea.style.height = "auto";
81+
expectedTextarea.style.height = "auto";
82+
83+
const maxScrollHeight = Math.max(
84+
receivedTextarea.scrollHeight,
85+
expectedTextarea.scrollHeight
86+
);
87+
88+
// 5пх -- число, чтобы высота была чуть выше, чтобы не показывался скролл
89+
const height = `${maxScrollHeight + 5}px`;
90+
receivedTextarea.style.height = height;
91+
expectedTextarea.style.height = height;
92+
}, [bug.receive, bug.expect]);
10593

10694
const attachments = useStoreMap({
10795
store: $attachmentsByBugId,

0 commit comments

Comments
 (0)