focus first input element in dialogs
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div mat-dialog-content>
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Text</mat-label>
|
||||
<textarea matInput [(ngModel)]="text"></textarea>
|
||||
<textarea matInput [(ngModel)]="text" #textElement></textarea>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div mat-dialog-actions align="end">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
@@ -6,12 +6,18 @@ import { MatDialogRef } from '@angular/material/dialog';
|
||||
templateUrl: './add-text-dialog.component.html',
|
||||
styleUrls: ['./add-text-dialog.component.scss']
|
||||
})
|
||||
export class AddTextDialogComponent {
|
||||
export class AddTextDialogComponent implements OnInit {
|
||||
text = "";
|
||||
|
||||
@ViewChild('textElement') textElement!: ElementRef;
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<string>){
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
window.setTimeout(() => this.textElement.nativeElement.focus(), 0);
|
||||
}
|
||||
|
||||
onSaveClick(): void {
|
||||
this.dialogRef.close(this.text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user