Skip to content
Merged
Show file tree
Hide file tree
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
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