[英]How to set focus on close button in primeng dialog
How to set focus on close button in primeng dialog after it's opened?打开后如何在primeng对话框中将焦点设置在关闭按钮上? I tried something like this, but it doesn't work.
我试过这样的东西,但它不起作用。 HTML:
HTML:
<p-dialog
[modal]="true"
[resizable]="true"
[draggable]="false"
header="header"
[(visible)]="dialogVisible"
(onHide)="closeDialog()"
(onShow)="openDialog()"
focusOnShow="false"
>
ts: TS:
constructor(private element: ElementRef<HTMLAnchorElement>) {}
openDialog() {
this.element.nativeElement.focus();
}
Update: I found solution how to set focus on this element更新:我找到了如何将焦点放在这个元素上的解决方案
openDialog() {
const element = this.elem.nativeElement.querySelectorAll('.ui-dialog-titlebar-close').item(0);
element.focus();
console.log(document.activeElement)
}
but it doesn't stick.但它不粘。 When I check focus inside openDialog it's set, but after that it still sets to another button.
当我在 openDialog 中检查焦点时,它已设置,但之后它仍设置为另一个按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.