Angular 5 : clicked button that triggers a dialog becomes highlighted after the dialog is closed

标签 angular angular5 angular-material-5

我注意到按钮获取类 cdk-focused 和 cdk-program-focused 添加之后它触发的对话框关闭。如果我点击任何地方,效果就会消失。

app.component.html [片段]

<mat-cell *matCellDef="let element">
  <span matTooltip="Delete" matTooltipPosition="right">
    <button mat-icon-button color="warn" (click)="openDeleteAssociationDialog()">
      <mat-icon>delete</mat-icon>
    </button>
  </span>
</mat-cell>

Illustration

最佳答案

这里更好的解决方案是使用配置属性 restoreFocus: false

matDialog.open(<your-component>, {
    restoreFocus: false
});

在这种情况下,当您使用 matDialogRef.close() 关闭 matDialog 时,焦点将不会应用于该删除按钮/图标。

引用:https://github.com/angular/components/issues/8420 - 它还有其他替代解决方案,包括 restoreFocus: false

关于 Angular 5 : clicked button that triggers a dialog becomes highlighted after the dialog is closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49329091/

相关文章:

angular - 从表单控件写入浏览器 URL

Angular @ViewChild 错误 'Cannot read property nativeElement of undefined"

angular - 如何在 Angular5 的 ng2-select 中列出客户端?

Angular Material 表自动滚动

javascript - 如何在mat-checkbox angular 5中实现全选

javascript - 在 Angular Material 自动完成显示中绑定(bind) 'this' 使用 Angular 5

javascript - Angular 仅显示结果数据数组的一部分

android - ( ionic )尝试读取文件时 Cordova-file-plugin 错误

angular - 通过 Share_Target 将图像从 whatsapp 共享到 angular 应用程序不起作用

Angular 5 始终加载缓存版本