Skip to content

Commit 02469d2

Browse files
committed
Update TextAreaDropdown.tsx
1 parent 7233317 commit 02469d2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

client/src/components/TextAreaDropdown.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,27 @@ function PrettyTextArea(props: Readonly<{
158158
const playerNames = usePlayerNames();
159159

160160
const textareaRef = useRef<HTMLTextAreaElement>(null);
161+
const prettyTextAreaRef = useRef<HTMLDivElement>(null);
162+
163+
useEffect(() => {
164+
const handleMouseMove = (e: MouseEvent) => {
165+
if (prettyTextAreaRef.current) {
166+
if (prettyTextAreaRef.current.contains(e.target as Node)) {
167+
setHover(true);
168+
} else {
169+
setHover(false);
170+
}
171+
}
172+
}
173+
document.addEventListener("mousemove", handleMouseMove);
174+
return () => document.removeEventListener("mousemove", handleMouseMove);
175+
}, []);
161176

162177
// Function to adjust textarea height
163178
const adjustHeight = () => {
164179
if (textareaRef.current) {
165180
textareaRef.current.style.height = "auto"; // Reset height
166-
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`; // Adjust to fit content
181+
textareaRef.current.style.height = `calc(.25rem + ${textareaRef.current.scrollHeight}px)`; // Adjust to fit content
167182
}
168183
};
169184

@@ -173,16 +188,19 @@ function PrettyTextArea(props: Readonly<{
173188
}, [props.field, writing, hover]);
174189

175190
return <div
191+
ref={prettyTextAreaRef}
176192
className="pretty-text-area"
177-
onMouseEnter={() => setHover(true)}
178-
onMouseLeave={() => setHover(false)}
179193
onTouchEnd={() => setWriting(true)}
180194
onFocus={() => setWriting(true)}
181-
onBlur={() => {setWriting(false); setHover(false)}}
195+
onBlur={() => setWriting(false)}
182196
>
183197
{(!writing && !hover) ?
184-
<div className="textarea">
185-
<StyledText noLinks={true}>{sanitizePlayerMessage(replaceMentions(props.field, playerNames))}</StyledText>
198+
<div
199+
className="textarea"
200+
>
201+
<StyledText noLinks={true}>
202+
{sanitizePlayerMessage(replaceMentions(props.field, playerNames))}
203+
</StyledText>
186204
</div>
187205
:
188206
<textarea

0 commit comments

Comments
 (0)