diff --git a/src/Core/Components/Wizard/FluentWizard.razor b/src/Core/Components/Wizard/FluentWizard.razor index 1de9b52666..26219978e1 100644 --- a/src/Core/Components/Wizard/FluentWizard.razor +++ b/src/Core/Components/Wizard/FluentWizard.razor @@ -32,7 +32,7 @@ { string buttonWidth = "80px;"; - @if (Value > 0) + @if (DisplayPreviousButton) { - @if (Value < _steps.Count - 1) + @if (DisplayNextButton) { protected virtual async Task OnStepChangeHandlerAsync(int targetIndex, bool validateEditContexts) { - var stepChangeArgs = new FluentWizardStepChangeEventArgs(targetIndex, _steps[targetIndex].Label); + var stepChangeArgs = new FluentWizardStepChangeEventArgs(targetIndex, _steps[targetIndex].Label); if (validateEditContexts) { @@ -341,4 +341,8 @@ private void SetCurrentStatusToStep(int stepIndex) return null; } + + private bool DisplayPreviousButton => Value > 0 && _steps[..Value].Any(i => !i.Disabled); + + private bool DisplayNextButton => Value < _steps.Count - 1 && _steps[(Value + 1)..].Any(i => !i.Disabled); } diff --git a/tests/Core/Wizard/FluentWizardTests.razor b/tests/Core/Wizard/FluentWizardTests.razor index 94c9f0e293..d15d0c96ac 100644 --- a/tests/Core/Wizard/FluentWizardTests.razor +++ b/tests/Core/Wizard/FluentWizardTests.razor @@ -477,6 +477,34 @@ Assert.Equal(indexFirstItem, currentIndex); } + [Theory] + [InlineData(true, true, true, 2)] + [InlineData(true, true, false, 1)] + [InlineData(true, false, false, 0)] + [InlineData(false, false, false, 0)] + public void FluentWizard_LastDisableSteps(bool firstEnabled, bool secondEnabled, bool thirdEnabled, int nbClicks) + { + // Arrange + var cut = Render(@ + + + + + + + ); + + // Act: Click + for (int i = 0; i < nbClicks; i++) + { + var buttonNext = cut.Find("fluent-button[appearance='accent']"); + buttonNext.Click(); + } + + // Assert + Assert.Contains("Done", cut.Markup); + } + private record TestRecord { [Range(1, 10)]