angular material mat-autocomplete on dialog opens panel
angular material mat-autocomplete on dialog opens panel
我有带自动完成字段的模式。
我使用 Angular 5 和 angular material 2。
加载模态时,第一个字段的面板始终打开...
如何避免这种情况?
我曾尝试在另一个字段上使用自动对焦属性,但它不起作用...
<form name="indexation">
<br>
<div class="row">
<div class="col-md-12">
<mat-form-field class="index-full-width">
<input
matInput
type="text"
[(ngModel)]="patientChoice"
placeholder="Patient"
aria-label="Patient"
[matAutocomplete]="autoPatient"
[formControl]="myControl">
<mat-autocomplete (optionSelected)="selectPat()" #autoPatient="matAutocomplete" [displayWith]="displayFnPat">
<mat-option *ngFor="let patient of filteredPatients | async" [value]="patient">
<span>{{ patient.lastName }}</span>
<small>{{patient.firstName}}</small> |
<span>né(e) le {{ patient.dateNaissance }}</span> |
<small>IPP: {{patient.ipp}}</small>
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
<br>
这个问题是否来自 material?
当有要显示的选项并且字段有焦点时,结果面板将自动打开。默认情况下,对话框会将焦点设置在第一个可聚焦元素上,因此我认为这就是为什么在对话框加载时自动完成会打开的原因。为避免这种情况,请在启动对话框时使用 MatDialogConfig 选项 autoFocus: false
。
我有带自动完成字段的模式。 我使用 Angular 5 和 angular material 2。 加载模态时,第一个字段的面板始终打开...
如何避免这种情况?
我曾尝试在另一个字段上使用自动对焦属性,但它不起作用...
<form name="indexation">
<br>
<div class="row">
<div class="col-md-12">
<mat-form-field class="index-full-width">
<input
matInput
type="text"
[(ngModel)]="patientChoice"
placeholder="Patient"
aria-label="Patient"
[matAutocomplete]="autoPatient"
[formControl]="myControl">
<mat-autocomplete (optionSelected)="selectPat()" #autoPatient="matAutocomplete" [displayWith]="displayFnPat">
<mat-option *ngFor="let patient of filteredPatients | async" [value]="patient">
<span>{{ patient.lastName }}</span>
<small>{{patient.firstName}}</small> |
<span>né(e) le {{ patient.dateNaissance }}</span> |
<small>IPP: {{patient.ipp}}</small>
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
<br>
这个问题是否来自 material?
当有要显示的选项并且字段有焦点时,结果面板将自动打开。默认情况下,对话框会将焦点设置在第一个可聚焦元素上,因此我认为这就是为什么在对话框加载时自动完成会打开的原因。为避免这种情况,请在启动对话框时使用 MatDialogConfig 选项 autoFocus: false
。