diff --git a/CodeBeam.MudBlazor.Extensions/Components/Stepper/MudStepper.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/Stepper/MudStepper.razor.cs index b2812235..6e92609c 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/Stepper/MudStepper.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/Stepper/MudStepper.razor.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using static MudBlazor.Colors; +using MudExtensions.Extensions; namespace MudExtensions { @@ -254,6 +255,38 @@ public async Task SetActiveIndex(int count, bool firstCompleted = false, bool sk } } + public async Task SetActiveStepByIndex(int index, bool firstCompleted = false, bool skipPreventProcess = false) + { + var stepChangeDirection = ( + index == ActiveIndex ? StepChangeDirection.None : + index > ActiveIndex ? StepChangeDirection.Forward : + StepChangeDirection.Backward + ); + + if (!skipPreventProcess && PreventStepChange != null && PreventStepChange.Invoke(stepChangeDirection)) + { + return; + } + + if (ActiveIndex == index || index < 0 || Steps.Count < index) + { + return; + } + + if (Steps.Count == index && IsAllStepsCompleted() == false) + { + return; + } + + if (_animate != null) + { + await _animate.Refresh(); + } + + ActiveIndex = index; + await ActiveStepChanged.InvokeAsync(ActiveIndex); + } + public async Task CompleteStep(int index, bool moveToNextStep = true) { var isActiveStep = (index == ActiveIndex); diff --git a/ComponentViewer.Docs/Pages/Examples/StepperExample1.razor b/ComponentViewer.Docs/Pages/Examples/StepperExample1.razor index 43d9d3ac..26cf4225 100644 --- a/ComponentViewer.Docs/Pages/Examples/StepperExample1.razor +++ b/ComponentViewer.Docs/Pages/Examples/StepperExample1.razor @@ -59,6 +59,7 @@ + @@ -111,6 +112,7 @@ bool _addResultStep = true; bool _customLocalization = false; Color _color = Color.Primary; + int _activeIndex = 0; private bool CheckChange(StepChangeDirection direction) {