Skip to content

Commit 4e5ea02

Browse files
committed
Fix refresh of root nodes
1 parent 9cd33bc commit 4e5ea02

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Source/Extensions/Blazorise.TreeView/Internal/_TreeViewNode.razor.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,12 @@ private async Task ReloadChildren( TreeViewNodeState<TNode> nodeState, IEnumerab
298298

299299
private async void OnChildrenChanged( object sender, NotifyCollectionChangedEventArgs e, TreeViewNodeState<TNode> nodeState, IEnumerable<TNode> childNodes )
300300
{
301-
bool shouldReloadRootNode = nodeState.Parent is null
302-
&& ( ( e.Action == NotifyCollectionChangedAction.Add && !nodeState.HasChildren )
303-
|| ( e.Action == NotifyCollectionChangedAction.Remove && childNodes?.Any() != true ) );
301+
bool nodeHadChildren = nodeState.HasChildren;
304302

305303
if ( !nodeState.HasChildren )
306304
{
307305
nodeState.HasChildren = true;
308306

309-
if ( shouldReloadRootNode )
310-
{
311-
await ParentTreeView.ReloadNode( nodeState.Node );
312-
return;
313-
}
314-
315307
if ( nodeState.Expanded || ExpandedNodes?.Contains( nodeState.Node ) == true )
316308
{
317309
nodeState.Expanded = true;
@@ -366,7 +358,14 @@ private async void OnChildrenChanged( object sender, NotifyCollectionChangedEven
366358
}
367359
}
368360

369-
nodeState.HasChildren = childNodes?.Any() == true;
361+
nodeState.HasChildren = nodeState.Children.Count > 0;
362+
363+
// Force refresh of a root node (no parent) if HasChildren changes
364+
if ( nodeState.Parent == null && nodeHadChildren != nodeState.HasChildren )
365+
{
366+
await ParentTreeView.ReloadNode( nodeState.Node );
367+
return;
368+
}
370369

371370
await InvokeAsync( StateHasChanged );
372371
}

0 commit comments

Comments
 (0)