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获取对话框标题,并在其上聚焦以支持可访问性。

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

相关内容

热门资讯

透视解谜!we poker辅助... 透视解谜!we poker辅助器下载,wejoker透视方法-果然是有辅助神器(哔哩哔哩)1、破解器...
透视曝光!wepoker高级辅... 透视曝光!wepoker高级辅助,wepoker辅助是真的吗-原来是有辅助软件(哔哩哔哩)1、脚本辅...
透视解迷!菠萝德州透视脚本,佛... 透视解迷!菠萝德州透视脚本,佛手大菠萝有挂吗-真是真的有辅助神器(哔哩哔哩)在进入菠萝德州透视脚本软...
透视曝光!德州局透视脚本下载安... 透视曝光!德州局透视脚本下载安装最新版本,哈糖大菠萝挂法-真是一直总是有辅助教程(哔哩哔哩);1、德...
透视专业!wpk透视怎么安装,... 透视专业!wpk透视怎么安装,wpk透视工作室-真是真的有辅助方法(哔哩哔哩)1、脚本辅助下载、免费...
透视详情!aapoker怎么提... 透视详情!aapoker怎么提高中牌率,aapoker能控制牌吗-都是真的是有辅助教程(哔哩哔哩);...
透视有挂!aapoker怎么控... 透视有挂!aapoker怎么控制牌,aapoker ai插件-确实真的有辅助方法(哔哩哔哩)1、操作...
透视分享!wpk德州局透视,微... 透视分享!wpk德州局透视,微扑克微乐辅助-真是真的是有辅助技巧(哔哩哔哩)德州局透视能透视中分为三...
透视详细!wepoker私人局... 透视详细!wepoker私人局外卦,we poker辅助器-好像是真的有辅助攻略(哔哩哔哩)1、超多...
透视关于!wepoker有没有... 透视关于!wepoker有没有挂,wepoker一直输的号能继续打吗-本来真的是有辅助工具(哔哩哔哩...