I have implemented a linear mat-stepper
in my application. It consists of some forms on each step to which you can navigate using next and previous buttons. You can go to next step by clicking on next button only when the current form's data is valid. There is no data validation on previous functionality.
You can't navigate between steps by clicking directly on the step headers or mat-step
. But the real problem is that mat-stepper
allows to navigate to next step using space
or enter
keys.
I want to prevent this, i.e., user should not be able to navigate to next step by key-press irrespective of whether the form is valid or not.
Following is my implementation of 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>
So, how can I prevent mat-step
to move forward on key-press?
Please let me know if you want any other information.