Skip to content

Commit

Permalink
Measure textarea before modifying DOM (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertrotter authored Aug 5, 2024
1 parent d87e880 commit 1e9bbfe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/input/src/calcTextareaHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export default function calcTextareaHeight(
minRows = 1,
maxRows = null
) {
if (!hiddenTextarea) {
hiddenTextarea = document.createElement('textarea');
targetElement.parentElement.appendChild(hiddenTextarea);
}

let {
paddingSize,
Expand All @@ -69,6 +65,11 @@ export default function calcTextareaHeight(
contextStyle
} = calculateNodeStyling(targetElement);

if (!hiddenTextarea) {
hiddenTextarea = document.createElement('textarea');
targetElement.parentElement.appendChild(hiddenTextarea);
}

hiddenTextarea.setAttribute('style', `${contextStyle};${HIDDEN_STYLE}`);
hiddenTextarea.value = targetElement.value || targetElement.placeholder || '';

Expand Down

0 comments on commit 1e9bbfe

Please sign in to comment.