Skip to content
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

bug(cdkTextareaAutosize): cdkTextareaAutosize does not resize when the placeholder or label is long #22042

Closed
jermowery opened this issue Feb 26, 2021 · 13 comments · Fixed by #22197
Labels
area: cdk/text-field feature This issue represents a new feature or feature request rather than a bug or bug fix G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround

Comments

@jermowery
Copy link
Contributor

Reproduction

https://stackblitz.com/edit/angular-2ebx1r?file=src/app/./text-field-autosize-textarea-example.html

Expected Behavior

What behavior were you expecting to see?

When a textarea has a long placeholder or label and the textarea using cdkTextareaAutosize, the text area should be auto-sized to support the length of the placeholder

Actual Behavior

What behavior did you actually see?

The text area does not auto-size to the placeholder or label used, and instead stays at the min number of rows and shows an internal (scrollbar?) the scroll through the placeholder

Environment

  • Angular: latest
  • CDK/Material: latest
  • Browser(s): all
  • Operating System (e.g. Windows, macOS, Ubuntu): all
@jermowery jermowery added the needs triage This issue needs to be triaged by the team label Feb 26, 2021
@jelbourn jelbourn added area: cdk/text-field feature This issue represents a new feature or feature request rather than a bug or bug fix G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround and removed needs triage This issue needs to be triaged by the team labels Feb 26, 2021
@jelbourn
Copy link
Member

@mmalerba @crisbeto we don't currently have the autosize directive respond to the placeholder text. Do you think this is something it should support?

@crisbeto
Copy link
Member

crisbeto commented Feb 26, 2021

It sounds reasonable to me, considering that the placeholder wraps on textarea, rather than truncating like on input.

Example

My concern is how we would handle the case where the placeholder is longer than the value. Would the height collapse when the user focuses the input and the placeholder disappears? It might also be weird if there's a short value with a long placeholder where clearing the input would cause the textarea to become taller.

@jermowery
Copy link
Contributor Author

I am thinking that whatever minimizes movement might make the most sense, so if the placeholder is long and the data is small we shouldn't necessarily snap back to a smaller size as soon as the user begins editing

@mmalerba
Copy link
Contributor

mmalerba commented Mar 2, 2021

Maybe we should just never let the textarea get smaller than the height with the placeholder. I'm not sure it really makes sense to let it go smaller

@jelbourn
Copy link
Member

jelbourn commented Mar 2, 2021

My inclination would also be to make this an option that's probably off by default in order to avoid breaking layouts in existing apps.

@mmalerba
Copy link
Contributor

mmalerba commented Mar 2, 2021

I would prefer not to have it be an option, just because it adds complexity. Depending on how its implemented, I'm fairly confident it won't break too many people. We could at least try a presubmit and see how it goes

@jelbourn
Copy link
Member

jelbourn commented Mar 3, 2021

That's reasonable, we can see what the presubmit shows and go from there

@jermowery
Copy link
Contributor Author

Is this currently being worked on? It is important for a launch we have coming up so I am trying to evaluate if we need to implement our own hacky fix or if the official fix will land first

@jelbourn
Copy link
Member

I don't think anyone has picked it up yet- if you wanted to take a pass at a PR I think the code would be pretty straightforward. Otherwise I can see if someone pon the team has time to take a look in the next week.

@jermowery
Copy link
Contributor Author

I will take a look at making a PR for this today

@jermowery
Copy link
Contributor Author

I was successful in implementing this within g3, I will work now on creating a PR which follows all of the various guidelines for GH and do a GTP

@jermowery
Copy link
Contributor Author

My attempted PR didn't work for this. I has been indicated to me that someone on the Angular team will take a look at this soon

andrewseguin pushed a commit that referenced this issue Mar 19, 2021
Fixes a bug with CdkTextareaAutosize where the textarea would not be autosized when using long placeholders

Fixes #22042

Cache the height with the placeholder

do calculation better

fix comment

Stop caching the placeholder because I can't make the caching approach work with view-engine

go back to the caching approach

Account for the input tests

fix lint error
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/text-field feature This issue represents a new feature or feature request rather than a bug or bug fix G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
4 participants