Does Angular Material have built in autosizing for textareas?

Dave Molinero picture Dave Molinero · Oct 24, 2017 · Viewed 13.1k times · Source

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?

Answer

Commercial Suicide picture Commercial Suicide · Oct 24, 2017

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