Pau*_*aul 8 angular angular5 angular-material-5
我注意到,在触发的对话框关闭后,该按钮会获得以cdk为重点的类和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>
Run Code Online (Sandbox Code Playgroud)
mad*_*mar 13
这里更好的解决方案是使用配置属性restoreFocus: false
matDialog.open(<your-component>, {
restoreFocus: false
});
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当您使用 matDialogRef.close() 关闭 matDialog 时,焦点将不会应用于该删除按钮/图标。
请参阅: https: //github.com/angular/components/issues/8420 - 它还有其他替代解决方案,包括restoreFocus: false.
小智 5
<button #changeButton mat-icon-button (click)="changeItem(element)" disableRipple>
<mat-icon>edit</mat-icon>
</button>
Run Code Online (Sandbox Code Playgroud)
{ ViewChild, ElementRef } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)
@ViewChild('changeButton') private changeButton: ElementRef;
Run Code Online (Sandbox Code Playgroud)
dialogRef.afterClosed().subscribe(result => {
this.changeButton['_elementRef'].nativeElement
.classList.remove('cdk-program-focused');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1880 次 |
| 最近记录: |