角材料对话框垫对话框动作位置

use*_*955 7 modal-dialog angular-material angular-components angular

我正在使用Angular Material Dialog 组件,使用 mat-dialog-content 和 mat-dialog-actions 来显示带有动作按钮的页脚。

如果我设置对话框的高度(例如 80%),则对话框操作会奇怪地高于默认值。

这是一个官方示例的分叉堆栈闪电战

我只是设置高度:80%

const dialogRef = this.dialog.open(DialogContentExampleDialog, {
  height: '80%',
  width: '520px'
});
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此处输入图片说明

在我看来,这是一个问题:) 但你有什么看法?是否可以轻松修复它?

谢谢!

Roc*_*lve 7

Github 问题跟踪此https://github.com/angular/components/issues/4609

包含 DanielHabenicht 的更清晰的修复(没有幻数) https://github.com/angular/components/issues/4609#issuecomment-528865962

// app.module.ts
import {MAT_DIALOG_DEFAULT_OPTIONS} from '@angular/material';
...
providers: [
    {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {panelClass: 'mat-dialog-override'}}
]
...


// overrides.scss or styles.scss
// This fixes https://github.com//issues/4609
.mat-dialog-override {
  height: 0px;
  mat-dialog-container {
    > :first-child {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    mat-dialog-content,
    div[mat-dialog-content] {
      flex-grow: 1;
      max-height: unset;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


JuN*_*uNe 5

您可以“伸展”您的mat-dialog-content.

<h1 mat-dialog-title>Hi {{data.name}}</h1>
<div mat-dialog-content style="height: calc(100% - 96px);">     <-- height of dialog minus title and actions height
  <p>What's your favorite animal?</p>
  <mat-form-field>
    <input matInput [(ngModel)]="data.animal">
  </mat-form-field>
</div>
<div mat-dialog-actions>
  <button mat-button (click)="onNoClick()">No Thanks</button>
  <button mat-button [mat-dialog-close]="data.animal" cdkFocusInitial>Ok</button>
</div>
Run Code Online (Sandbox Code Playgroud)