Skip to content

Commit

Permalink
Fix handleContentSizeChange function
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Apr 15, 2024
1 parent 7b19778 commit 8abd0ee
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
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};
Expand Down Expand Up @@ -569,6 +568,11 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
}
}, [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;
Expand Down

0 comments on commit 8abd0ee

Please sign in to comment.