I want to navigate the stepper only through the next and back buttons.
I can't get this to work since users can also click each step label to navigate to any step. I can't use linear, since it requires each step to have a formArray
or FormGroup
.
I have tried <mat-step (click)="$event.stopPropagation()">
.
For each mat-step , the stepControl attribute can be set to the top level AbstractControl that is used to check the validity of the step. There are two possible approaches. One is using a single form for stepper, and the other is using a different form for each step.
The <mat-stepper>, an Angular Directive, is used to create a wizard like work-flow steps.
Angular content stepper provides a wizard-like workflow by dividing the content into logical steps. The material stepper is responsible for logic on the CDK stepper's foundation that drives the stepped workflow. The material stepper extends the CDK stepper and a material design style.
Add this to your style sheet. I was trying to disable the header navigation. Tried many things but this hack worked. You can try this till Angular Material Team support this feature.
::ng-deep .mat-horizontal-stepper-header{ pointer-events: none !important; }
Use a linear
stepper with completed=false
steps. When the user presses your button, programattically complete the step and move to the next one.
This way you don't need to mess with CSS pointer events. In our app, that resulted in accessibility problems with NVDA.
<mat-horizontal-stepper linear #stepper> <mat-step completed="false"> <ng-template matStepLabel>Step 1</ng-template> <app-some-child (nextClicked)="nextClicked($event)" ></app-some-child> </mat-step> <mat-step> <ng-template matStepLabel>Step 2</ng-template> <app-some-other-child></app-some-other-child> </mat-step> </mat-horizontal-stepper> export class AppComponent implements OnInit { @ViewChild('stepper') stepper: MatStepper; nextClicked(event) { // complete the current step this.stepper.selected.completed = true; // move to next step this.stepper.next(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With