Skip to content

Commit

Permalink
fix: Text area only shows the last line of the message for very long …
Browse files Browse the repository at this point in the history
…texts #31252 #31257 (#31262)
  • Loading branch information
Sayan4444 authored Jan 2, 2024
1 parent 9d6cf47 commit 92a8de7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const shadowStyleBase: CSSProperties = {

export const useAutoGrow = (
ref: RefObject<HTMLTextAreaElement>,
shadowRef: RefObject<HTMLTextAreaElement>,
shadowRef: RefObject<HTMLDivElement>,
hideTextArea?: boolean,
): {
textAreaStyle: CSSProperties;
Expand All @@ -37,8 +37,7 @@ export const useAutoGrow = (
if (!textarea) {
return;
}

const handleInput = () => {
const updateTextareaSize = () => {
const { value } = textarea;
const { current: shadow } = shadowRef;
if (!shadow) {
Expand All @@ -51,10 +50,10 @@ export const useAutoGrow = (
.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>');
};

textarea.addEventListener('input', handleInput);
updateTextareaSize();
textarea.addEventListener('input', updateTextareaSize);
return () => {
textarea.removeEventListener('input', handleInput);
textarea.removeEventListener('input', updateTextareaSize);
};
}, [ref, shadowRef]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const MessageBox = ({

const textareaRef = useRef<HTMLTextAreaElement>(null);
const messageComposerRef = useRef<HTMLElement>(null);
const shadowRef = useRef(null);
const shadowRef = useRef<HTMLDivElement>(null);

const storageID = `messagebox_${room._id}${tmid ? `-${tmid}` : ''}`;

Expand Down

0 comments on commit 92a8de7

Please sign in to comment.