CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.
https://mudextensions.codebeam.org/
MIT License
358 stars 61 forks source link

MudStepper PreventStepChangeAsync send index of clicked/selected MudStep #335

Closed rf-0 closed 5 months ago

rf-0 commented 6 months ago

With mudstep there are 2 ways of navigating, through the Action buttons at the bottom or through the Step icons at the top. If you have validation on a per step basis and the user tries to use the Step icons at the top to jump to a later step, it is hard to validate this without knowning which Step the user clicked / is trying to navigate to. At the moment PreventStepChangeAsync only tells the direction and if you do a _stepper!.GetActiveIndex() it returns the current index and theres no way to know which index the user is trying to jump to. This isnt a problem with the bottom Action buttons navigation since it will always be the next step. If you try to do the validation on the ActiveStepChanged which happens afterwards PreventStepChangeAsync , it is already too late and even if you validate and call SetActiveStepByIndex(), you still get a flash screen (not ideal...) since its basically rendering the step the user clicked and then sending the user back to the one set by SetActiveStepByIndex.

Solution:

PreventStepChangeAsync

[Parameter] public Func<StepChangeDirection, **int SelectedIndex**, Task<bool>> PreventStepChangeAsync { get; set; }

fellsoft commented 5 months ago

+1 - Just came across the exact same challenge trying to validate step changes.

fellsoft commented 5 months ago

Fantastic, thank you :)