Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular material stepper: disable header navigation

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()">.

like image 788
Shaniqwa Avatar asked Oct 25 '17 13:10

Shaniqwa


People also ask

What is stepControl in Mat stepper?

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.

What is matstepper?

The <mat-stepper>, an Angular Directive, is used to create a wizard like work-flow steps.

What is stepper in angular?

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.


2 Answers

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; } 
like image 136
Shahzaib Shahid Avatar answered Sep 26 '22 12:09

Shahzaib Shahid


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();       }     }  
like image 25
James Young Avatar answered Sep 25 '22 12:09

James Young