Search code examples
angulartextareaangular-materialautosize

Does Angular Material have built in autosizing for textareas?


I am able to import MatTextareaAutosize from Angular Material, but I see nothing about it in the docs and have not found a way to use it.

I expected to use something like this:

<mat-form-field>
    <textarea matInput matAutosize></textarea>
</mat-form-field>

Is there a way to get autosizing text boxes with angular material?


Solution

  • The answer is simple: it should be matTextareaAutosize, not just matAutosize: https://github.com/angular/material2/blob/master/src/material-examples/input-autosize-textarea/input-autosize-textarea-example.html

    Caution! Apparently, this will be removed in version 7 and is currently deprecated https://material.angular.io/components/input/api#MatTextareaAutosize

    PS: See also comment from @Simon_Weaver regarding the deprecation