0

[![在此处输入图像描述][1]][1]我想为文本区域设置最大高度,因此当用户继续添加文本时,如果达到最大高度,它将添加一个滚动。但是我目前的实现是它拉伸了 modal ,所以如果我添加更多文本,modal 就会变得太长。

我们如何使模态不会被拉伸?谢谢。

html

 <div fxLayout="row" fxLayoutAlign="start start" class="full-width question-text" fxLayoutGap="12px">
          <mat-form-field style="height: auto; overflow: hidden;" class="pr-4" appearance="outline">
            <mat-label>Comments</mat-label>
            <div
            style="
              margin-right: 10px;
              overflow-y: auto;
              height: auto;
              max-height: 200px;
            "
          >
          <textarea cdkTextareaAutosize
          matTextareaAutosize
          matInput
          formControlName="comment"
          [required]="isCommentRequired()"
        ></textarea>
          </div>
4

2 回答 2

1

你试过 matAutosizeMinRows 和 matAutosizeMaxRows

<textarea matInput
              matTextareaAutosize
              [matAutosizeMinRows]="min"
              [matAutosizeMaxRows]="max"></textarea>
  </mat-form-field>
于 2020-05-12T09:18:14.807 回答
1

overflow-y:scroll把它放在textarea css中,这不是一个角度问题,而是一个CSS问题,也overflow-y: auto从父div中删除。

于 2020-05-12T09:15:13.680 回答