AngularMaterial的MatDialog无法阅读和聚焦可访问性。
创始人
2024-10-28 09:01:15
0

为了让Angular Material的MatDialog支持可访问性,需要将以下示例代码添加到MatDialog的组件中:

import { Component, OnInit, Inject, ViewChild, AfterViewInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

@Component({
  selector: 'app-example-dialog',
  templateUrl: './example-dialog.component.html',
  styleUrls: ['./example-dialog.component.scss']
})
export class ExampleDialogComponent implements OnInit, AfterViewInit {

  @ViewChild('dialogTitle') dialogTitle: any;

  constructor(
    public dialogRef: MatDialogRef,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) { }

  ngOnInit() {
  }

  ngAfterViewInit() {
    this.dialogRef.afterOpened().subscribe(_ => {
      this.dialogTitle.nativeElement.focus();
    });
  }

}

在上面的代码中,我们可以看到:

  • 通过ViewChild引用对话框标题。
  • 在ngAfterViewInit生命周期钩子函数中,使用afterOpened()方法订阅对话框打开事件。
  • 在事件中,通过nativeElement获取对话框标题,并在其上聚焦以支持可访问性。

在以上示例代码中,我们可以根据自己的需求进行一些更改以适应我们的应用程序。

相关内容

热门资讯

透视练习!德普之星怎么设置埋牌... 透视练习!德普之星怎么设置埋牌,德普之星透视辅助软件(透视)确实有脚本方法(哔哩哔哩)1、让任何用户...
透视技法!wepoker怎么提... 透视技法!wepoker怎么提高运气,we poker辅助器下载(透视)竟然有脚本挂(哔哩哔哩)一、...
透视学习!hhpoker有没有... 透视学习!hhpoker有没有作必弊辅助,hh poker辅助器先试用(透视)竟然是有透视脚本(哔哩...
透视法子!德扑圈透视,德普之星... 透视法子!德扑圈透视,德普之星透视免费(透视)原来是真的透视工具(哔哩哔哩)1、德普之星透视免费公共...
透视经验!wepoker轻量版... 透视经验!wepoker轻量版透视方法,wepoker私人局规律(透视)一直是真的透视技巧(哔哩哔哩...
透视秘籍!wepoker免费辅... 透视秘籍!wepoker免费辅助器,wepoker怎么买辅助(透视)果然是真的脚本脚本(哔哩哔哩);...
透视学习!wepoker软件靠... 透视学习!wepoker软件靠谱么,wepoker透视有没有(透视)一直有透视脚本(哔哩哔哩)1、用...
透视绝活儿!德扑圈透视挂,德普... 透视绝活儿!德扑圈透视挂,德普之星私人局辅助免费(透视)竟然真的是有脚本工具(哔哩哔哩)1、德普之星...
透视教材!wepoker黑侠辅... 透视教材!wepoker黑侠辅助器,wepoker提高好牌率(透视)其实真的有透视神器(哔哩哔哩)1...
透视阶段!佛手在线大菠萝辅助,... 透视阶段!佛手在线大菠萝辅助,pokemmo辅助脚本(透视)一贯有脚本神器(哔哩哔哩)1、透视阶段!...