Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/BootstrapBlazor/Components/TreeView/TreeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

@if (Items == null)
{
if (ShowSkeleton)
if (_init)
{

}
else if (ShowSkeleton)
{
<SkeletonTree AdditionalAttributes="AdditionalAttributes"></SkeletonTree>
}
Expand Down
13 changes: 12 additions & 1 deletion src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
.AddClass(item.CssClass)
.Build();

private bool _init;

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down Expand Up @@ -351,7 +353,6 @@ protected override async Task OnParametersSetAsync()
{
if (IsReset)
{
_rows = null;
TreeNodeStateCache.Reset();
}
else
Expand All @@ -374,9 +375,19 @@ protected override async Task OnParametersSetAsync()
}
}

//重新计算节点
_rows = null;

// 设置 ActiveItem 默认值
ActiveItem ??= Items.FirstOrDefaultActiveItem();
ActiveItem?.SetParentExpand<TreeViewItem<TItem>, TItem>(true);
_init = true;
}
else
{
_rows = null;
TreeNodeStateCache.Reset();
ActiveItem = null;
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/UnitTest/Components/TreeViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public void Items_Ok()
pb.Add(a => a.Items, TreeFoo.GetTreeItems());
});
cut.Contains("li");

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.Items, null);
pb.Add(a => a.ShowSkeleton, false);
});
Assert.Equal("", cut.Markup);
}

[Fact]
Expand Down
Loading