material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[TextField] Fix Backspacing after line break in multiline causes heig…

Open Hukumchand-Narwre opened this issue 2 weeks ago • 1 comments

This is my first Open source contribution. This PR fixes an issue in TextField height when the multiline prop is passed.

Root Cause

In safari when textarea height is reduced programmatically, Safari updates the height but does not recalculate text line wrapping & caret position. Chrome handles this correctly

Proposed Fix

We can force textline wrapping recalculation in Safari by changing the textArea width.

const selectionStart = textarea.selectionStart;
const selectionEnd = textarea.selectionEnd;
const tempValue = textarea.value;

textarea.value = '';
textarea.offsetHeight; // Force reflow
textarea.value = tempValue;

// Restore selection
if (document.activeElement === textarea) {
  textarea.setSelectionRange(selectionStart, selectionEnd);
}

Fixes

Fixes #45293

Hukumchand-Narwre avatar Dec 07 '25 06:12 Hukumchand-Narwre

Netlify deploy preview

https://deploy-preview-47443--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+224B(+0.04%) 🔺+98B(+0.06%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by :no_entry_sign: dangerJS against 0e49052ac40a99ca46cb3bfae20fdab96787e9c9

mui-bot avatar Dec 07 '25 06:12 mui-bot

Thank you, @mj12albert, for reviewing the PR. Required changes are done, please review again

Hukumchand-Narwre avatar Dec 17 '25 05:12 Hukumchand-Narwre