MatDialogRef 文本区域滚动到底部

MatDialogRef textarea scrolls to bottom

我有一个应用程序,我在其中使用 MatDialogRef 将组件作为对话框打开。

对话框显示了很长的文本,但由于某种原因,文本区域滚动到底部。 如果它不是动态创建的组件,则不会发生这种情况。

举个例子:https://stackblitz.com/edit/matdialogref-textarea-scroll-issue

我希望有人能解释发生了什么以及如何解决它,所以 textarea 留在滚动条的顶部。

提前致谢!

来自 @angular/material 对话框文档:

Once a dialog opens, the dialog will automatically focus the first tabbable element.

You can control which elements are tab stops with the tabindex attribute

只需在模态 div 上添加一个 tabindex=0:

<div class="dialog" tabindex="0">
    <textarea class="texta" [(ngModel)]="data"></textarea>
</div>

Here's a Working Demo for your ref.

Here's another thread for your ref: