[TextareaAutosize] Support max height - #49106
Open
stop1love1 wants to merge 1 commit into
Open
Conversation
The component forces `overflow: hidden` whenever the content fits the height it computes, which ignores a CSS `max-height` shorter than that height. The content was then clipped with no way to scroll to it. Compare the computed height with the resolved `max-height` and keep the textarea scrollable when it is clipped, the same way it already behaves once `maxRows` is reached. Closes mui#43719
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43719
Problem
TextareaAutosizemeasures its content and then writes bothheightandoverflowon the textarea:overflowis only left scrollable whenmaxRowsclamps the height. A CSSmax-heightis invisible to that computation, so the browser clips the box atmax-heightwhile the component keepsoverflow: hiddenon it — the text below the fold becomes unreachable, exactly as reported in the issue.Solution
Read
max-heightfrom the computed style that is already being fetched, and treat "the height we are about to apply is taller thanmax-height" the same way the component already treats "maxRowsreached": keep the textarea scrollable.The comparison is done against
outerHeightStyle, sobox-sizingis accounted for automatically —max-heightandheightresolve against the same box.getComputedStylereturnsmax-heightas a resolved computed value, not a used value, so layout-dependent values (percentages,calc()mixing percentages) come back unresolved and can't be compared with a pixel height. Those fall back to the current behaviour rather than guessing; a test locks that in.No public API change, and no extra layout read —
computedStylewas already being queried.Testing
Three tests added to the existing jsdom
layoutsuite. The first two fail onmaster(expected … 'overflow' of '', but got 'hidden') and pass with the fix; the third documents the non-absolutemax-heightfallback.pnpm eslint,pnpm typescriptandprettier --checkare clean on the touched files, and the neighbouringTextField/InputBase/Input/OutlinedInput/FilledInputsuites still pass (260 tests).Happy to follow up with a docs demo for
max-heightif you'd like one in the same PR.