Skip to content

Commit 8f93d36

Browse files
author
Mohammadreza Sarvari
committed
fix(TextareaAutosize): prevent placeholder from affecting height
1 parent 93c9748 commit 8f93d36

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/mui-material/src/TextareaAutosize/TextareaAutosize.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
8989
}
9090

9191
hiddenTextarea.style.width = computedStyle.width;
92-
hiddenTextarea.value = textarea.value || props.placeholder || 'x';
92+
hiddenTextarea.value = textarea.value || 'x';
9393
if (hiddenTextarea.value.slice(-1) === '\n') {
9494
// Certain fonts which overflow the line height will cause the textarea
9595
// to report a different scrollHeight depending on whether the last line
@@ -126,7 +126,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
126126
const overflowing = Math.abs(outerHeight - innerHeight) <= 1;
127127

128128
return { outerHeightStyle, overflowing };
129-
}, [maxRows, minRows, props.placeholder]);
129+
}, [maxRows, minRows]);
130130

131131
const didHeightChange = useEventCallback(() => {
132132
const textarea = textareaRef.current;
@@ -155,6 +155,9 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
155155
textarea.style.height = `${outerHeightStyle}px`;
156156
}
157157
textarea.style.overflow = textareaStyles.overflowing ? 'hidden' : '';
158+
if (!textarea.value) {
159+
textarea.style.whiteSpace = 'nowrap';
160+
}
158161
}, [calculateTextareaStyles]);
159162

160163
const frameRef = React.useRef(-1);

0 commit comments

Comments
 (0)