Skip to content

Commit 8080408

Browse files
ArgoZhangAiYuZhen
andauthored
fix(SelectTree): shoud set the default active node by Value on first render (#5004)
* fix: 修复 Value 设置 IsActive 状态逻辑 * chore: bump version 9.2.1-beta02 Co-Authored-By: AiZhen <[email protected]> * test: 增加单元测试 * refactor: 更改判定条件 --------- Co-authored-by: AiZhen <[email protected]>
1 parent 9e6b9ae commit 8080408

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
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>9.2.1-beta01</Version>
4+
<Version>9.2.1-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Select/SelectTree.razor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private async Task TriggerItemChanged(Func<TreeViewItem<TValue>, bool> predicate
232232
var currentItem = GetExpandedItems().FirstOrDefault(predicate);
233233
if (currentItem != null)
234234
{
235+
currentItem.IsActive = true;
235236
await ItemChanged(currentItem);
236237
}
237238
}

test/UnitTest/Components/SelectTreeTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ public void IsPopover_Ok()
190190
cut.DoesNotContain("data-bs-toggle=\"dropdown\"");
191191
}
192192

193+
[Fact]
194+
public void IsActive_Ok()
195+
{
196+
var items = TreeFoo.GetTreeItems();
197+
var cut = Context.RenderComponent<SelectTree<TreeFoo>>(builder =>
198+
{
199+
builder.Add(p => p.Items, items);
200+
builder.Add(p => p.Value, new TreeFoo() { Id = "1020", Text = "Navigation Two" });
201+
});
202+
var nodes = cut.FindAll(".tree-content");
203+
Assert.Equal(3, nodes.Count);
204+
Assert.Contains("active", nodes[1].ClassName);
205+
}
206+
193207
private List<TreeViewItem<string>> BindItems { get; } =
194208
[
195209
new TreeViewItem<string>("Test1")

0 commit comments

Comments
 (0)