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.
<md-input-container> Text area does not shrink when all text is cleared #8135
Here's the initial md-input-container component with a text area:
<md-input-container class="md-block">
<label>Enter some text and hit enter a few times. Then delete all the text.</label>
<textarea rows="5"></textarea>
</md-input-container>
I then enter some text and hit enter a few times:
I've set rows="5" on the textarea so it only grows to show those 5 rows.
However, when I clear all the text it doesn't shrink again:
Thanks for the report. This is the "intended" behaviour for the current implementation. We have a PR that will address this issue. You can keep track of it here.
Thanks @crisbeto. I do like the way it starts at 1 row and expands to the max row though. For example we use this in a chat application where it starts off at 1 row but can expand to 3 rows. Is there a way we can also keep this behavior or make it optional at least? But to shrink back down to 1 row once all the text is cleared. Sort of like slack and other chat apps work:
It should work like that if you removed the rows attribute. Although you should keep in mind that in this case it won't have a max height. If that's not intended, you can use this as a temporary workaround until #7991 gets merged:
Remove the rows attribute.
Add the following somewhere in your CSS:
textarea.md-input{max-height:/* whatever max height you want */;overflow: auto;}
@crisbeto the css workaround doesn't seems to work any more on v1.1.0-rc4-master-2806ec8. The max-height and overflow is being respected, but it is not possible to scroll inside textarea.
@char0n that's because of a preventDefault on the textarea in the old implementation (it's removed in the new one). It's a hack, but you can work around it with a directive that removes the scroll listener. It's not ideal, but hopefully it won't be necessary for very long:
Hey @crisbeto , I just pulled this in 1.1.0-rc.5. It does what it says on the tin but one thing I noticed is that the height sort of jerks a bit. It looks like you're setting an inline css style on the textarea element to set the height and padding. So the height starts off at the default and then you seem to override it which is causing it to move which doesn't look great. Any suggestions on how to prevent this? Maybe if you set the default height and padding a bit earlier?
Activity
crisbeto commentedon Apr 20, 2016
Thanks for the report. This is the "intended" behaviour for the current implementation. We have a PR that will address this issue. You can keep track of it here.
cmacdonnacha commentedon Apr 21, 2016
Thanks @crisbeto. I do like the way it starts at 1 row and expands to the max row though. For example we use this in a chat application where it starts off at 1 row but can expand to 3 rows. Is there a way we can also keep this behavior or make it optional at least? But to shrink back down to 1 row once all the text is cleared. Sort of like slack and other chat apps work:
Start off with 1 row:

As you type more text it expands to 2 rows:

And if you clear the text it goes back to 1 row:

Would your PR allow for this behavior?
crisbeto commentedon Apr 21, 2016
It should work like that if you removed the
rowsattribute. Although you should keep in mind that in this case it won't have a max height. If that's not intended, you can use this as a temporary workaround until #7991 gets merged:rowsattribute.cmacdonnacha commentedon Apr 21, 2016
Ah ok great. Thanks for that and well done on the PR.
char0n commentedon May 29, 2016
@crisbeto the css workaround doesn't seems to work any more on v1.1.0-rc4-master-2806ec8. The max-height and overflow is being respected, but it is not possible to scroll inside textarea.
Here is codepen to demonstrate: http://codepen.io/anon/pen/xOKzYo
Tested on Chrome: 51.0.2704.63 m
@crisbeto do you have any idea how to make it work again ? Thanks
crisbeto commentedon May 29, 2016
@char0n that's because of a
preventDefaulton the textarea in the old implementation (it's removed in the new one). It's a hack, but you can work around it with a directive that removes the scroll listener. It's not ideal, but hopefully it won't be necessary for very long:char0n commentedon May 29, 2016
@crisbeto yep, that does the trick. Thanks. I'll follow this issue until PR is merged.
* Changes the textarea behavior to consider the "rows" attribute as t…
cmacdonnacha commentedon Jun 2, 2016
So will this be in merged into the next release?
crisbeto commentedon Jun 2, 2016
It should be.
cmacdonnacha commentedon Jun 29, 2016
Hey @crisbeto , I just pulled this in 1.1.0-rc.5. It does what it says on the tin but one thing I noticed is that the height sort of jerks a bit. It looks like you're setting an inline css style on the textarea element to set the height and padding. So the height starts off at the default and then you seem to override it which is causing it to move which doesn't look great. Any suggestions on how to prevent this? Maybe if you set the default height and padding a bit earlier?
See gif (happens every time the view loads):

feat(textarea): support shrinking and resizing