You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
textarea with min_rows grows slightly too small, scrolls when it shouldn't #5919
I have a texarea control inside an md-input-container that wants the autogrow behavior, but if the text gets larger than a few rows, the textarea is slightly smaller.
More specifically: we have a <textarea rows="5">. If I start entering text into it, with 1-4 lines of text, all the text is visible and there's empty space at the bottom. With 5 lines of text, the textarea is full and all 5 lines of text are visible. But when I add a 6th line of text, the textarea remains having rows=5 and so the top line is truncated. As I then add more rows of text, the textarea grows again adding 1 row of actual size for each line of text I add, so it always remains 1 row too small (i.e. I can see all the text except the first line), until I hit 16 lines of text, at which point the textarea again fails to grow and now the top 2 lines are missing (scrolled out of view).
My codebase is still on AM 0.11 but looking at the code on master (currently:
What's going on is the path where the textarea supplies an initial rows attribute calculates lineHeight by looking at the initial clientHeight of the element, and thereafter it uses that lineHeight as a divisor against the node.scrollHeight to set the rows attribute.
In my case (my box, browser, styles, etc), lineHeight is 29 but each subsequent line of text I add to the textarea only adds 26 to its scrollHeight. So, with some integer-floor stair-steppiness, dividing by 29 instead of 26 means we end up truncating by 1 and then 2 and then more rows as the content grows.
I'm not a CSS/DOM expert but it seems to me the initial clientHeight is interpreted as the height of just a row of text, but also includes some padding (3px in my case) that is not repeated on additional rows. I don't know the right way to calculate the height of this padding. Since the lineHeight is calculated only once when the textarea is ostensibly empty: instead of taking the element height of an empty textarea as the lineHeight, perhaps we should calculate lineHeight as the difference in heights between a textarea containing no text and one line of text, that is, look at node.scrollHeight when the textarea is empty and get oneLineHeight, then temporarily set the textarea value to '\n' and look again at node.scrollHeight and get twoLineHeight, then set lineHeight = twoLineHeight - oneLineHeight?
Note that this behavior only affects the textarea if you supply an initial rows=, and not the default auto-sizing path.
Activity
EladBezalel commentedon Apr 18, 2016
@devversion @crisbeto is this solved?
crisbeto commentedon Apr 18, 2016
It should be once we merge #7991, I changed the logic for determining the height there so it doesn't use the rows to calculate it.
* Changes the textarea behavior to consider the "rows" attribute as t…
feat(textarea): support shrinking and resizing