Repository navigation
FluentTreeItem clear selected attribute #5401
Replies: 1 comment 1 reply
|
You can do it without JS by clearing the tree's selection from C# when you navigate away. Going by the v4 source ( // FluentTreeItem.GetFluentTreeItem(...)
builder.AddAttribute(4, "InitiallySelected", owner.SelectedItem == item);So if you bind @implements IDisposable
@inject NavigationManager Nav
<FluentTreeView Items="@items"
@bind-SelectedItem="selected"
@bind-SelectedItem:after="OnSelected" />
@code {
private IEnumerable<ITreeViewItem> items = ...;
private ITreeViewItem? selected;
protected override void OnInitialized() => Nav.LocationChanged += OnLocationChanged;
private void OnSelected()
{
if (selected is not null)
{
Nav.NavigateTo(selected.Id);
}
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
// Left the page this item points to (via the nav menu, FluentAppBar, back button...)
if (selected is not null && !Nav.Uri.EndsWith(selected.Id, StringComparison.OrdinalIgnoreCase))
{
selected = null;
InvokeAsync(StateHasChanged);
}
}
public void Dispose() => Nav.LocationChanged -= OnLocationChanged;
}Adjust the URL comparison to however your item ids map to routes. If you build the tree with Note: I wrote this from reading the current v4 code on |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am using
FluentTreeView.Here is the situation: after the first click on a
FluentTreeItem, I navigate to a page usingNavigationManager.NavigateTo(item.Id);, and theselectedattribute is added to the HTML element. As a result, I cannot click on that tree item again. This is the expected behavior, and it suits my needs.However, after navigating to another page using the "nav" or "FluentAppBar," I want to be able to return by clicking that
FluentTreeItemagain; but since it retains theselectedattribute, the click does not register.How can I programmatically remove this attribute without using
JSRuntime?All reactions