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.

<md-input-container> Text area does not shrink when all text is cleared #8135

Closed

Description

@cmacdonnacha

See codepen example.

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>

image

I then enter some text and hit enter a few times:

image

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:
image

Activity

  1. crisbeto commented on Apr 20, 2016

    @crisbeto
    Member

    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.

  2. self-assigned this
    on Apr 20, 2016
  3. added this to the 1.1.1 milestone on Apr 20, 2016
  4. added
    pr: merge ready
    has: Pull Request
    and removed
    pr: merge ready
    on Apr 20, 2016
  5. modified the milestones: 1.1.1, on Apr 21, 2016
  6. cmacdonnacha commented on Apr 21, 2016

    @cmacdonnacha
    Author

    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:
    image

    As you type more text it expands to 2 rows:
    image

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

    Would your PR allow for this behavior?

  7. crisbeto commented on Apr 21, 2016

    @crisbeto
    Member

    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:

    1. Remove the rows attribute.
    2. Add the following somewhere in your CSS:
    textarea.md-input {
      max-height: /* whatever max height you want */;
      overflow: auto;
    }
  8. cmacdonnacha commented on Apr 21, 2016

    @cmacdonnacha
    Author

    Ah ok great. Thanks for that and well done on the PR.

  9. char0n commented on May 29, 2016

    @char0n

    @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

  10. crisbeto commented on May 29, 2016

    @crisbeto
    Member

    @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:

    .directive('textarea', function($timeout){
     return {
       restrict: 'E',
       link: function(scope, element){
         $timeout(function(){
            element.off('scroll');
         }, 0, false);
       }
     }
    });
  11. char0n commented on May 29, 2016

    @char0n

    @crisbeto yep, that does the trick. Thanks. I'll follow this issue until PR is merged.

  12. added a commit that references this issue on Jun 1, 2016
    af2e4aa
  13. cmacdonnacha commented on Jun 2, 2016

    @cmacdonnacha
    Author

    So will this be in merged into the next release?

  14. crisbeto commented on Jun 2, 2016

    @crisbeto
    Member

    It should be.

  15. cmacdonnacha commented on Jun 29, 2016

    @cmacdonnacha
    Author

    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):
    angular-material-textarea-jumps

  16. removed this from the - Backlog milestone on Feb 23, 2019
  17. added a commit that references this issue on Sep 28, 2024
    ce07651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has: Pull Request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions