Skip to content

Commit 1189cf0

Browse files
authored
feat(Step): add SetStepIndex method (#7619)
* doc: 更新 xml 注释 * feat(Step): add SetStepIndex method * chore: bump version 10.3.1-beta04 * test: 更新单元测试 * test: 更新单元测试
1 parent 3445b76 commit 1189cf0

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.3.1-beta03</Version>
4+
<Version>10.3.1-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Step/Step.razor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ public async Task<int> Next()
155155
return _currentStepIndex;
156156
}
157157

158+
/// <summary>
159+
/// <para lang="zh">设置当前步骤索引 <see cref="StepIndex"/> 值</para>
160+
/// <para lang="en">Set current step index <see cref="StepIndex"/> value</para>
161+
/// </summary>
162+
/// <param name="index"></param>
163+
public async Task SetStepIndex(int index)
164+
{
165+
_currentStepIndex = Math.Max(0, Math.Min(Items.Count, index));
166+
if (IsFinished && OnFinishedCallback != null)
167+
{
168+
await OnFinishedCallback();
169+
}
170+
StateHasChanged();
171+
}
172+
158173
/// <summary>
159174
/// <para lang="zh">重置步骤方法</para>
160175
/// <para lang="en">Reset Step Method</para>

src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
196196
public Func<TreeViewItem<TItem>, Task<IEnumerable<TreeViewItem<TItem>>>>? OnExpandNodeAsync { get; set; }
197197

198198
/// <summary>
199-
/// <inheritdoc/>
199+
/// <inheritdoc cref="IModelEqualityComparer{TItem}.CustomKeyAttribute"/>
200200
/// </summary>
201201
[Parameter]
202202
public Type CustomKeyAttribute { get; set; } = typeof(KeyAttribute);
203203

204204
/// <summary>
205-
/// <inheritdoc/>
205+
/// <inheritdoc cref="IModelEqualityComparer{TItem}.ModelEqualityComparer"/>
206206
/// </summary>
207207
[Parameter]
208208
public Func<TItem, TItem, bool>? ModelEqualityComparer { get; set; }

test/UnitTest/Components/StepTest.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void Step_Method()
128128
}
129129

130130
[Fact]
131-
public void FinishedTemplate_Ok()
131+
public async Task FinishedTemplate_Ok()
132132
{
133133
bool finished = false;
134134
var cut = Context.Render<Step>(pb =>
@@ -143,8 +143,29 @@ public void FinishedTemplate_Ok()
143143
});
144144
});
145145
var step = cut.Instance;
146-
cut.InvokeAsync(() => step.Next());
147-
cut.WaitForAssertion(() => cut.Contains("Finished-Template"));
146+
await cut.InvokeAsync(() => step.Next());
147+
cut.Contains("Finished-Template");
148+
Assert.True(finished);
149+
}
150+
151+
[Fact]
152+
public async Task SetStepIndex()
153+
{
154+
bool finished = false;
155+
var cut = Context.Render<Step>(pb =>
156+
{
157+
pb.Add(a => a.Items, GetStepItems);
158+
pb.Add(a => a.StepIndex, 2);
159+
pb.Add(a => a.OnFinishedCallback, () =>
160+
{
161+
finished = true;
162+
return Task.CompletedTask;
163+
});
164+
});
165+
var step = cut.Instance;
166+
await cut.InvokeAsync(() => step.SetStepIndex(1));
167+
Assert.False(finished);
168+
await cut.InvokeAsync(() => step.SetStepIndex(3));
148169
Assert.True(finished);
149170
}
150171

0 commit comments

Comments
 (0)