Skip to content

Navs

Nav

Bit.BlazorUITreeTreeView

A navigation pane (Nav) provides links to the main areas of an app or site, and can also be used as a TreeView to show parent-child data in a tree. It renders a hierarchy of any depth, keeps its selection in sync with the current URL (matched exactly, by prefix, by wildcard or by regular expression) or leaves it to the app in the manual mode, and expands one branch at a time or all of them at once. The items can be grouped under expandable headers, reduced to a rail of icons, separated by rules, and rendered through templates, and the whole tree is reachable from the keyboard with the arrow keys, Home, End and type-ahead.

Notes

The BitNav is a Multi-API component which can accept the list of Items in 3 different ways:
1. The BitNavItem class
2. A Custom Generic class
3. The BitNavOption component

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

The nav renders the tree given to Items as a list of links. Each BitNavItem carries its Text, an optional IconName, Description and Url, and the items nested in its ChildItems turn it into an expandable node. An item with IsEnabled set to false is rendered but neither clickable nor selectable.

FitWidth & FullWidth

By default the nav takes the width its container gives it. FitWidth shrinks it to the width of its widest item, which is what a nav sitting next to other content usually wants, and FullWidth stretches it over the whole container.



FitWidth




FullWidth

Grouped

The Grouped render type turns every root item into a group header: a full-width button with a bottom border that expands and collapses the group instead of navigating. Only the root level changes; everything below it keeps rendering as ordinary nav items.

Separator

An item with IsSeparator renders a horizontal rule in place of a link, which groups the items around it without giving that group a header. It is skipped by the keyboard navigation and reported to assistive technologies as a separator rather than as a nav item.

Manual Mode

In the default Automatic mode the nav keeps the selection in sync with the current URL. The Manual mode hands that over to the app: the clicked item becomes the selected one, the initial selection comes from DefaultSelectedItem, and SelectedItem two-way binds the selection so it can be driven from anywhere else on the page.



Basic




Two-Way Bind


IconOnly

IconOnly collapses the nav to a rail of icons: the texts, the descriptions and the expand chevrons are all hidden, so only the icon of each item is left. The text still reaches the pointer as the item's tooltip and the screen reader through the item's accessible name.


SingleExpand

SingleExpand turns the nav into an accordion: expanding a branch collapses the one that was open before it, so a deep tree never grows past a single open path. ExpandAll is a no-op while this mode is on, since it would break that rule.

AllExpanded & NoCollapse

AllExpanded opens every branch of the tree on the first render. NoCollapse goes further and removes the expand/collapse buttons altogether, together with the space they reserve at the start of each item, which is how a nav that is always fully open is rendered.

Chevron & Indentation

ReversedChevron moves the expand chevron to the trailing side of the item, and ChevronDownIconName (or ChevronDownIcon, for an external icon library) replaces the icon it renders while keeping its rotation. The indentation is arithmetic: IndentValue is the padding added per level of depth, IndentPadding is the space a childless item reserves in place of the chevron, and IndentReversedPadding replaces it while the chevron is reversed.



ReversedChevron




Custom chevron icon




IndentValue & IndentPadding

Custom Templates

HeaderTemplate replaces the content of the group headers in the Grouped render type and ItemTemplate replaces the content of every ordinary item, both receiving the item as their context. The matching HeaderTemplateRenderMode and ItemTemplateRenderMode decide whether the template renders inside the item's own link (Normal) or takes its place entirely (Replace), and the Template of a single item overrides both for that item alone.



Header Template (Grouped)




Item Template




Item Template (Replace)

Public API

A reference to the nav exposes its state as methods: ExpandAll and CollapseAll open or close the whole tree (or a single subtree, when given an item), ExpandItem, CollapseItem and ToggleItem drive a single item, IsItemExpanded reports whether one is open, SelectItem selects one without a click, and FocusItem moves the keyboard focus to it, opening the branches it is nested in when it is not on screen yet.


Events

OnItemClick fires for every click on an item, OnSelectItem only when the selection actually changes, and OnItemToggle when a branch is expanded or collapsed. Setting Reselectable makes the select events fire again for an item that is already selected.

Clicked Item:
Selected Item:
Toggled Item: N/A

URL Matching

In the Automatic mode the nav selects the item whose URL points at the current page. Match sets how those URLs are compared for the whole nav, and the Match of an item overrides it: Exact asks for the same URL, Prefix also matches everything below it, Wildcard reads the URL of the item as a pattern in which ? stands for a single character other than /, * for any number of them and ** for any number of characters at all, slashes included, and Regex reads it as a regular expression. The comparison ignores the query string, and Exact and Prefix also ignore the letter case and a trailing slash; Wildcard and Regex run the pattern exactly as it was written, so those two tell the letter cases apart and see a trailing slash as a difference. AdditionalUrls gives an item other URLs to light up on. The navs below are all matched against the URL of this page.



Exact (the default)




Prefix




Wildcard




Regex




Match of an item & AdditionalUrls



Color

Color paints the parts that carry the nav's identity: the icons and the border of the selected item. Accent is a separate role that paints the hovered and the selected item: a background, foreground or border role only tints it, so the colorful icon set shows through, while a semantic role fills it and takes its text and icon along. Both accept every value of BitColor, including the background, foreground and border roles that are not listed here.



Primary




Secondary




Tertiary




Info




Success




Warning




SevereWarning




Error





Accent:


Primary




Success




Warning




Error

External Icons

Besides the built-in icons of IconName, the Icon parameter of an item accepts the CSS classes of any external icon library, such as FontAwesome or Bootstrap Icons, and takes precedence over IconName. The same applies to the ChevronDownIcon of the nav itself.


FontAwesome Icons:





Bootstrap Icons:

Size

Size scales the metrics of every part of the nav at once: the height of the items, the size of their text and description, and the height and text of the group headers.



Small




Medium




Large

Style & Class

Style and Class reach the root element, the Style and Class of an item reach the list element of that item, and the Styles and Classes objects reach every part of the nav separately: the root, the item container and its selected variant, the item and its selected variant, the item icon and text, the toggle button and its chevron icon, the description, the group header and its text, and the separator.



Component's Style & Class:







Item's Style & Class:





Styles & Classes:



RTL

Setting Dir to Rtl flips the nav and everything it renders: the chevrons, the indentation of the levels and the direction of the arrow keys, so the Right arrow steps out of a branch and the Left arrow steps into it.

API

Every parameter, public member, sub-class and enum this component exposes.

BitNav parameters

Name Type Default value Description
Accent BitColor? null The accent color of the nav.
AllExpanded bool false Expands all items when they are first rendered. Items that arrive later are expanded as they arrive, while the items already on screen keep whatever the user has expanded or collapsed in the meantime.
ChevronDownIcon BitIconInfo? null The icon for the chevron-down element of each nav item. Takes precedence over ChevronDownIconName when both are set.
ChevronDownIconName string? null The custom icon name of the chevron-down element of each nav item.
ChildContent RenderFragment? null Items to render as children.
Classes BitNavClassStyles? null Custom CSS classes for different parts of the BitNav component.
CollapseAriaLabel string? null The default aria-label of the expand/collapse button of an expanded item. The CollapseAriaLabel of the item takes precedence over this value, and when neither is provided the text of the item is used.
Color BitColor? null The general color of the nav that is only used for colored parts like icons.
DefaultSelectedItem TItem? null The initially selected item in manual mode.
ExpandAriaLabel string? null The default aria-label of the expand/collapse button of a collapsed item. The ExpandAriaLabel of the item takes precedence over this value, and when neither is provided the text of the item is used.
FitWidth bool false Renders the nav in a width to only fit its content.
FullWidth bool false Renders the nav in full width of its container element.
HeaderTemplate RenderFragment<TItem>? null Used to customize how content inside the group header is rendered.
HeaderTemplateRenderMode BitNavItemTemplateRenderMode BitNavItemTemplateRenderMode.Normal The render mode of the custom HeaderTemplate.
IconOnly bool false Only renders the icon of each nav item.
IndentPadding int 27 The indentation padding in px for items without children (compensation space for chevron icon).
IndentReversedPadding int 4 The indentation padding in px for items in reversed mode.
IndentValue int 16 The indentation value in px for each level of depth of child item.
Items IList<TItem> new List<TItem>() A collection of items to display in the BitNav component.
ItemTemplate RenderFragment<TItem>? null Used to customize how content inside the item is rendered.
ItemTemplateRenderMode BitNavItemTemplateRenderMode BitNavItemTemplateRenderMode.Normal The render mode of the custom ItemTemplate.
Match BitNavMatch? null Gets or sets a value representing the global URL matching behavior of the nav. The Match of an item takes precedence over this value, and when neither is provided the URL of an item has to match the current one exactly.
Mode BitNavMode BitNavMode.Automatic Determines how the navigation will be handled.
NameSelectors BitNavNameSelectors<TItem>? null Names and selectors of the custom input type properties.
NoCollapse bool false Hides all collapse/expand buttons and remove their spaces at the start of each node.
OnItemClick EventCallback<TItem> Callback invoked when an item is clicked.
OnItemToggle EventCallback<TItem> Callback invoked when an item is expanded or collapsed.
OnSelectItem EventCallback<TItem> Callback invoked when an item is selected.
Options RenderFragment? null Alias of ChildContent.
RenderType BitNavRenderType BitNavRenderType.Normal The way to render nav items.
Reselectable bool false Enables recalling the select events when the same item is selected.
ReversedChevron bool false Reverses the location of the expander chevron.
SelectedItem TItem? null Selected item to show in the BitNav.
Size BitSize? null The size of the nav items.
SingleExpand bool false Enables the single-expand mode in the BitNav.
Styles BitNavClassStyles? null Custom CSS styles for different parts of the BitNav component.

BitNav public members

Name Type Default value Description
CollapseAll Action<TItem? item> Collapses all items and children.
CollapseItem Func<TItem, Task> Collapses an item, and does nothing when it is already collapsed.
ExpandAll Action<TItem? item> Expands all items and children in non-SingleExpand mode.
ExpandItem Func<TItem, Task> Expands an item, and does nothing when it is already expanded.
FocusItem Func<TItem, ValueTask> Moves the focus to an item of the nav, opening the branches it is nested in when it is not rendered yet.
IsItemExpanded Func<TItem, bool> Whether an item is currently expanded.
SelectItem Func<TItem?, Task> Selects an item programmatically, exactly like a click on that item would in the manual mode.
ToggleItem Func<TItem, Task> Toggles an item.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters.
Id string? null Gets or sets the unique identifier for the component's root element.
IsEnabled bool true Gets or sets a value indicating whether the component is enabled and can respond to user interaction.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitNavNameSelectors<TItem> properties

Name Type Default value Description
AriaCurrent BitNameSelectorPair<TItem, BitNavAriaCurrent?> new(nameof(BitNavItem.AriaCurrent)) The AriaCurrent field name and selector of the custom input class.
AriaLabel BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.AriaLabel)) The AriaLabel field name and selector of the custom input class.
Class BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Class)) The Class field name and selector of the custom input class.
ChildItems BitNameSelectorPair<TItem, List<TItem>?> new(nameof(BitNavItem.ChildItems)) The ChildItems field name and selector of the custom input class.
CollapseAriaLabel BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.CollapseAriaLabel)) The CollapseAriaLabel field name and selector of the custom input class.
Data BitNameSelectorPair<TItem, object?> new(nameof(BitNavItem.Data)) The Data field name and selector of the custom input class.
Description BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Description)) The Description field name and selector of the custom input class.
ExpandAriaLabel BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.ExpandAriaLabel)) The ExpandAriaLabel field name and selector of the custom input class.
ForceAnchor BitNameSelectorPair<TItem, bool?> new(nameof(BitNavItem.ForceAnchor)) The ForceAnchor field name and selector of the custom input class.
Icon BitNameSelectorPair<TItem, BitIconInfo?> new(nameof(BitNavItem.Icon)) The Icon field name and selector of the custom input class.
IconName BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.IconName)) The IconName field name and selector of the custom input class.
IsEnabled BitNameSelectorPair<TItem, bool?> new(nameof(BitNavItem.IsEnabled)) The IsEnabled field name and selector of the custom input class.
IsExpanded BitNameSelectorPair<TItem, bool?> new(nameof(BitNavItem.IsExpanded)) The IsExpanded field name and selector of the custom input class.
IsSeparator BitNameSelectorPair<TItem, bool?> new(nameof(BitNavItem.IsSeparator)) The IsSeparator field name and selector of the custom input class.
Key BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Key)) The Key field name and selector of the custom input class.
Match BitNameSelectorPair<TItem, BitNavMatch?> new(nameof(BitNavItem.Match)) The Match field name and selector of the custom input class.
Style BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Style)) The Style field name and selector of the custom input class.
Target BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Target)) The Target field name and selector of the custom input class.
Template BitNameSelectorPair<TItem, RenderFragment<TItem>?> new(nameof(BitNavItem.Template)) The Template field name and selector of the custom input class.
TemplateRenderMode BitNameSelectorPair<TItem, BitNavItemTemplateRenderMode?> new(nameof(BitNavItem.TemplateRenderMode)) The TemplateRenderMode field name and selector of the custom input class.
Text BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Text)) The Text field name and selector of the custom input class.
Title BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Title)) The Title field name and selector of the custom input class.
Url BitNameSelectorPair<TItem, string?> new(nameof(BitNavItem.Url)) The Url field name and selector of the custom input class.
AdditionalUrls BitNameSelectorPair<TItem, IEnumerable<string>?> new(nameof(BitNavItem.AdditionalUrls)) The AdditionalUrls field name and selector of the custom input class.

BitIconInfo properties

Name Type Default value Description
Name string? null Gets or sets the name of the icon.
BaseClass string? null Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty.
Prefix string? null Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty.

BitColor enum

Name Value Description
Primary 0 Info Primary general color.
Secondary 1 Secondary general color.
Tertiary 2 Tertiary general color.
Info 3 Info general color.
Success 4 Success general color.
Warning 5 Warning general color.
SevereWarning 6 SevereWarning general color.
Error 7 Error general color.
PrimaryBackground 8 Primary background color.
SecondaryBackground 9 Secondary background color.
TertiaryBackground 10 Tertiary background color.
PrimaryForeground 11 Primary foreground color.
SecondaryForeground 12 Secondary foreground color.
TertiaryForeground 13 Tertiary foreground color.
PrimaryBorder 14 Primary border color.
SecondaryBorder 15 Secondary border color.
TertiaryBorder 16 Tertiary border color.

BitSize enum

Name Value Description
Small 0 The small size.
Medium 1 The medium size.
Large 2 The large size.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.