Hi Victoria,
Using the same item for navigation and hierarchy expansion is not a best practice, it often leads to confusion, and we don't recommend it. Moreover, the suggested feature is not a common UX pattern that users may expect.
Thus, consider an extra child item instead, so that the parent is only for expansion.
If you really need to share functionality in a single item, then a PanelBar HeaderTemplate may help you use part of the parent item for navigation and part of it for expansion. The border in the following example is for demonstration purposes only.
@inject NavigationManager NavigationManager
<div style="width: 30%;">
<TelerikPanelBar Data="@Items"
@bind-ExpandedItems="@ExpandedItems">
<PanelBarBindings>
<PanelBarBinding Level="0">
<HeaderTemplate>
@{
var item = (PanelBarItem)context;
<span style="border:1px solid blue;flex: 1 1 100%;"
@onclick="@( () => OnParentItemClick(item.ProgrammaticUrl) )">
@item.Text
</span>
}
</HeaderTemplate>
</PanelBarBinding>
</PanelBarBindings>
</TelerikPanelBar>
</div>
<div style="width: 30%;">
<TelerikPanelBar Data="@Items"
@bind-ExpandedItems="@ExpandedItems">
<PanelBarBindings>
<PanelBarBinding Level="0">
<HeaderTemplate>
@{
var item = (PanelBarItem)context;
<span style="border:1px solid blue;"
@onclick="@( () => OnParentItemClick(item.ProgrammaticUrl) )">
@item.Text
</span>
}
</HeaderTemplate>
</PanelBarBinding>
</PanelBarBindings>
</TelerikPanelBar>
</div>
@code {
private List<PanelBarItem> Items { get; set; } = new();
private IEnumerable<object> ExpandedItems { get; set; } = new List<object>();
public class PanelBarItem
{
public int Id { get; set; }
public string Text { get; set; } = string.Empty;
public int? ParentId { get; set; }
public bool HasChildren { get; set; }
public ISvgIcon? Icon { get; set; }
public string Url { get; set; } = string.Empty;
public string ProgrammaticUrl { get; set; } = string.Empty;
}
private void OnParentItemClick(string url)
{
if (!string.IsNullOrEmpty(url))
{
NavigationManager.NavigateTo(url);
}
}
private List<PanelBarItem> LoadFlatData()
{
List<PanelBarItem> items = new List<PanelBarItem>();
items.Add(new PanelBarItem()
{
Id = 1,
Text = "Section Name 1",
ParentId = null,
HasChildren = true,
Icon = SvgIcon.Code,
ProgrammaticUrl = "weather"
});
items.Add(new PanelBarItem()
{
Id = 2,
Text = "Page 111",
ParentId = 1,
HasChildren = false,
Icon = SvgIcon.Cs,
Url = "/"
});
items.Add(new PanelBarItem()
{
Id = 3,
Text = "Page 222",
ParentId = 1,
HasChildren = false,
Icon = SvgIcon.Html5,
Url = "counter"
});
items.Add(new PanelBarItem()
{
Id = 4,
Text = "Page 333",
ParentId = 1,
HasChildren = false,
Icon = SvgIcon.Css,
Url = "weather"
});
return items;
}
protected override void OnInitialized()
{
Items = LoadFlatData();
ExpandedItems = new List<object>() { Items[1] };
base.OnInitialized();
}
}
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.