test(ui): add external filtering tests for TreeView (R8)

This commit is contained in:
Joseph Doherty
2026-03-23 02:35:39 -04:00
parent 4e5b5facec
commit 08d511f609
2 changed files with 133 additions and 0 deletions

View File

@@ -104,6 +104,12 @@ else
ApplyInitialExpansion(_items);
}
}
// Clear selection if the selected key no longer exists in the current items tree
if (Selectable && SelectedKey != null && _items is not null && !KeyExistsInTree(_items, SelectedKey))
{
_ = SelectedKeyChanged.InvokeAsync(null);
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -133,6 +139,20 @@ else
}
}
private bool KeyExistsInTree(IReadOnlyList<TItem> items, object key)
{
foreach (var item in items)
{
if (key.Equals(KeySelector(item)))
return true;
var children = ChildrenSelector(item);
if (children is { Count: > 0 } && KeyExistsInTree(children, key))
return true;
}
return false;
}
private void ApplyInitialExpansion(IReadOnlyList<TItem> items)
{
foreach (var item in items)