Skip to content

[TextareaAutosize] Prevent placeholder from affecting height #46556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
11 changes: 5 additions & 6 deletions packages/mui-material/src/TextareaAutosize/TextareaAutosize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
}

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

return { outerHeightStyle, overflowing };
}, [maxRows, minRows, props.placeholder]);
}, [maxRows, minRows]);

const didHeightChange = useEventCallback(() => {
const textarea = textareaRef.current;
Expand Down Expand Up @@ -155,6 +155,9 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
textarea.style.height = `${outerHeightStyle}px`;
}
textarea.style.overflow = textareaStyles.overflowing ? 'hidden' : '';
if (!textarea.value) {
textarea.style.whiteSpace = 'nowrap';
}
}, [calculateTextareaStyles]);

const frameRef = React.useRef(-1);
Expand Down Expand Up @@ -274,10 +277,6 @@ TextareaAutosize.propTypes /* remove-proptypes */ = {
* @ignore
*/
onChange: PropTypes.func,
/**
* @ignore
*/
placeholder: PropTypes.string,
/**
* @ignore
*/
Expand Down
Loading