Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
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

Closed

Description

@metamatt

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:

lineHeight = element.prop('clientHeight');
) it still looks the same.

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

  1. added this to the 1.0.4 milestone on Jan 9, 2016
  2. added
    P1: urgent
    on Jan 15, 2016
  3. modified the milestones: 1.0.4, on Jan 15, 2016
  4. EladBezalel commented on Apr 18, 2016

    @EladBezalel
    Member

    @devversion @crisbeto is this solved?

  5. crisbeto commented on Apr 18, 2016

    @crisbeto
    Member

    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.

  6. added
    pr: merge ready
    has: Pull Request
    and removed
    pr: merge ready
    on Apr 18, 2016
  7. modified the milestones: , Deprecated on Apr 20, 2016
  8. added a commit that references this issue on Jun 1, 2016
    af2e4aa
  9. added a commit that references this issue on Jun 2, 2016
    ce07651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1: urgenthas: Pull Request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions