Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TreeView): reset Items to null #4894

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions 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 @@ -377,6 +379,13 @@ protected override async Task OnParametersSetAsync()
// 设置 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