diff --git a/knowledge-base/hierarchical-breadcrumb-dropdowns-blazor.md b/knowledge-base/hierarchical-breadcrumb-dropdowns-blazor.md new file mode 100644 index 000000000..8d6f6c2e5 --- /dev/null +++ b/knowledge-base/hierarchical-breadcrumb-dropdowns-blazor.md @@ -0,0 +1,102 @@ +--- +title: Hierarchical Breadcrumb in Blazor +description: Learn how to customize the Breadcrumb for Blazor by embedding dropdowns within Breadcrumb items to optimize user interaction and functionality. +type: how-to +page_title: Hierarchical Breadcrumb in Blazor +slug: hierarchical-breadcrumb-dropdowns-blazor +tags: breadcrumb, blazor, customization, dropdown, itemtemplate, hierarchical +res_type: kb +ticketid: 1652751 +--- + +## Environment + + + + + + + + +
ProductBreadcrumb for Blazor
+ +## Description + +Adding custom components like dropdowns to Breadcrumb crumbs can improve user interaction. + +This KB article answers the following questions: +* Is it possible to achieve a hierarchical structure in the Breadcrumb component? +* Is it possible to embed custom components inside Breadcrumb crumbs? +* How to use the `ItemTemplate` to add dropdowns to Breadcrumb items? + +## Solution + +To embed dropdowns in the Breadcrumb "crumbs", use an [`ItemTemplate`]({%slug breadcrumb-templates%}#itemtemplate). This template allows you to customize the Breadcrumb items, and include other components such as dropdowns. + +````CSHTML +@*The dropdown's appearance is customized to blend with the Breadcrumb by adjusting the border color and preventing text decoration changes on hover.*@ + + + + @if (context.Items != null && context.Items.Any()) + { + var values = new List { context.Text }.Concat(context.Items.Select(x => x.Text)); + var value = context.SelectedChildren?.Text ?? context.Text; + + + + + + } + else + { + @context.Text + } + + + + + +@code { + private IEnumerable Items { get; set; } = new List(); + + private void OnValueChanged(BreadcrumbItem item, string value) + { + item.SelectedChildren = item.Items.FirstOrDefault(x => x.Text == value); + } + + protected override void OnInitialized() + { + Items = new List + { + new BreadcrumbItem { Text = "Telerik UI for Blazor" }, + new BreadcrumbItem { Text = "Components", Items = new List { new BreadcrumbItem { Text = "AutoComplete" }, new BreadcrumbItem { Text = "Calendar" }, new BreadcrumbItem { Text = "Grid" } } }, + new BreadcrumbItem { Text = "Templates" }, + }; + } + + public class BreadcrumbItem + { + public string Text { get; set; } + public List Items { get; set; } + public BreadcrumbItem SelectedChildren { get; set; } + } +} +```` + +## See Also + +* [Breadcrumb Templates](https://docs.telerik.com/blazor-ui/components/breadcrumb/templates#itemtemplate) +* [DropDownList Overview](https://docs.telerik.com/blazor-ui/components/dropdownlist/overview)