简体   繁体   English

在 (click) 和 (focus) 事件上打开 Mat-dialog

[英]open Mat-dialog on (click) and (focus) events

I have a form field that opens a Mat Dialog, and I want it to open on mouse click or keyboard (tab button press), I tried using both (click) and (focus) events, but the input keeps opening sometimes after closing it.我有一个打开 Mat 对话框的表单域,我希望它在鼠标单击或键盘(按 Tab 键按钮)时打开,我尝试同时使用 (click) 和 (focus) 事件,但有时在关闭它后输入仍然打开.

<input #loc formControlName="loc" (click)="openDialog()" (focus)="openDialog()" placeholder="Enter you location" matInput required  [readonly]="true"/>
openDialog(): void {
    this.locInput.focused = !this.locaInput.focused;
    if (this.locInput.focused) {
    const dialogRef = this.dialog.open(locDialogComponent, {
      width: '524px',
      data: {
        location: this.location;
      }
    });

    dialogRef.afterClosed().subscribe(result => {
    });
}

如果您希望它在已经聚焦输入的同时按下 Tab 按钮时触发,您可以简单地通过

<input (keydown.Tab)="openDialog()" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM