From 8abd0ee63a2b9f49175f07b129d0b478faaf230b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Mon, 15 Apr 2024 12:22:57 +0200 Subject: [PATCH] Fix handleContentSizeChange function --- src/MarkdownTextInput.web.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index 891b6b9c..e1b68482 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -310,9 +310,8 @@ const MarkdownTextInput = React.forwardRef( return; } - const hostNode = (divRef.current.firstChild as HTMLElement) ?? divRef.current; - const newWidth = hostNode.offsetWidth; - const newHeight = hostNode.offsetHeight; + const newWidth = divRef.current.offsetWidth; + const newHeight = divRef.current.offsetHeight; if (newHeight !== dimensions.current?.height || newWidth !== dimensions.current.width) { dimensions.current = {height: newHeight, width: newWidth}; @@ -569,6 +568,11 @@ const MarkdownTextInput = React.forwardRef( } }, [autoFocus]); + useEffect(() => { + // update content size when the input styles change + handleContentSizeChange(); + }, [handleContentSizeChange, inputStyles]); + useEffect(() => { if (!divRef.current || !selection || (contentSelection.current && selection.start === contentSelection.current.start && selection.end === contentSelection.current.end)) { return;