我在我的应用程序中实现了线性mat-stepper
。它包含每个步骤的一些表单,您可以使用下一个和上一个按钮导航到这些表单。只有当当前表单的数据有效时,您才能通过单击下一步按钮进入下一步。以前的功能没有数据验证。
您无法通过直接单击步骤标题或 来在步骤之间导航mat-step
。但真正的问题是允许使用或键mat-stepper
导航到下一步。space
enter
我想防止这种情况发生,即无论表单是否有效,用户都不能通过按键导航到下一步。
以下是我对 mat-stepper 的实现:
- stepperForm.html
<mat-vertical-stepper class="sidebar-internal" #stepper linear (selectionChange)="selectionChange($event)">
<!-- a list of all the current steps -->
<mat-step
*ngFor="let item of stepList; let i = index"
[label]="item?.label"
>
</mat-step>
<!-- example of how it was done previously -->
</mat-vertical-stepper>
<div class="button-wrapper">
<button
class="btn button-secondary previous-button"
(click)="goPrev(stepper)"
[disabled]="hidePrevBtn"
type="button"
>
<mat-icon>west</mat-icon> Previous
</button>
<button
class="btn button-primary next-button"
(click)="goNext(stepper)"
[disabled]="hideNextBtn"
type="button"
>
Next <mat-icon>east</mat-icon>
</button>
</div>
那么,我怎样才能防止mat-step
在按键上前进呢?
如果您需要任何其他信息,请告诉我。