test(ui): add external filtering tests for TreeView (R8)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user