Home > OS >  How to control mat-stepper navigation between steps without Linear mode?
How to control mat-stepper navigation between steps without Linear mode?

Time:11-15

Is it possible to validate a step before going to the next one and the linear mode is not enabled ?

When i disabled the linear mode of the stepper and set its property to false, i don't have the control to validate navigation between steps.

CodePudding user response:

No and yes.

Of course you can try to implement a hacky approach which basically mimics the exact same behavior of linear mode. By why should you do that? That's exactly what linear mode is for as mentioned in the docs (https://material.angular.io/components/stepper/overview#linear-stepper):

The linear attribute can be set on mat-stepper to create a linear stepper that requires the user to complete previous steps before proceeding to following steps.

So my suggestion is: If you want to perform some validation before navigation to the next step, just use linear mode instead of basically reimplementing it.

Update after feedback from comment

If you have specific stages where you don't need the linear step validation, you can just omit putting the stepControl directive or set [optional]="true" to it. (reference https://material.angular.io/components/stepper/overview#optional-step)

  • Related