Skip to content

Commit 7125001

Browse files
authored
Stepper Add SetActiveStepByIndex Method (#161)
1 parent 6f85cff commit 7125001

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CodeBeam.MudBlazor.Extensions/Components/Stepper/MudStepper.razor.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text;
1212
using System.Threading.Tasks;
1313
using static MudBlazor.Colors;
14+
using MudExtensions.Extensions;
1415

1516
namespace MudExtensions
1617
{
@@ -254,6 +255,38 @@ public async Task SetActiveIndex(int count, bool firstCompleted = false, bool sk
254255
}
255256
}
256257

258+
public async Task SetActiveStepByIndex(int index, bool firstCompleted = false, bool skipPreventProcess = false)
259+
{
260+
var stepChangeDirection = (
261+
index == ActiveIndex ? StepChangeDirection.None :
262+
index > ActiveIndex ? StepChangeDirection.Forward :
263+
StepChangeDirection.Backward
264+
);
265+
266+
if (!skipPreventProcess && PreventStepChange != null && PreventStepChange.Invoke(stepChangeDirection))
267+
{
268+
return;
269+
}
270+
271+
if (ActiveIndex == index || index < 0 || Steps.Count < index)
272+
{
273+
return;
274+
}
275+
276+
if (Steps.Count == index && IsAllStepsCompleted() == false)
277+
{
278+
return;
279+
}
280+
281+
if (_animate != null)
282+
{
283+
await _animate.Refresh();
284+
}
285+
286+
ActiveIndex = index;
287+
await ActiveStepChanged.InvokeAsync(ActiveIndex);
288+
}
289+
257290
public async Task CompleteStep(int index, bool moveToNextStep = true)
258291
{
259292
var isActiveStep = (index == ActiveIndex);

ComponentViewer.Docs/Pages/Examples/StepperExample1.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
<MudItem xs="12" sm="4" Style="box-shadow: rgba(240, 46, 170, 0.4) -3px 3px;">
6161
<MudStack Spacing="4">
62+
<MudNumericField @bind-Value="_activeIndex" Label="Change ActiveIndex" @bind-Value:after="(() => _stepper.SetActiveStepByIndex(_activeIndex))" Margin="Margin.Dense" />
6263
<MudCheckBox @bind-Checked="_linear" Color="Color.Primary" Label="Linear" Dense="true" />
6364
<MudCheckBox @bind-Checked="_disableAnimation" Color="Color.Primary" Label="Disable Animation" Dense="true" />
6465
<MudCheckBox @bind-Checked="_disablePreviousButton" Color="Color.Primary" Label="Disable Previous Step Action Button" Dense="true" />
@@ -111,6 +112,7 @@
111112
bool _addResultStep = true;
112113
bool _customLocalization = false;
113114
Color _color = Color.Primary;
115+
int _activeIndex = 0;
114116

115117
private bool CheckChange(StepChangeDirection direction)
116118
{

0 commit comments

Comments
 (0)