Navs
Nav
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 (exact, prefix, wildcard or regex) or leaves it to the app, groups items under headers, shrinks to a rail of icons, and is fully operable from the keyboard with the tree-view keys.
Notes
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
FitWidth & FullWidth
Grouped & Separator
Manual Mode
IconOnly
Expand & Collapse
Chevron & Indentation
Custom Templates
Public API
Events
Selected Item:
Toggled Item: N/A
URL Matching
Accessibility
Keyboard: Tab moves between the items, ↑ ↓ Home End walk the visible ones, → opens a branch and then steps into it, ← closes it and then steps out, * opens every sibling, and typing jumps to the next item starting with it. Collapse Navs: the branch that holds the current page takes the look of the selection, so the reader never loses it.
Cascading parameters
Color
External Icons
Size
Style & Class
RTL
CSS variables
The public custom properties this component reads off its root, for what no parameter covers.
Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property:
set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it,
or on the Style of one instance to restyle that one alone. Leave a variable unset and the component falls back to the theme token beside it.
BitNav CSS variables
| Name | Default value | Description |
|---|---|---|
| --bit-Nav-color | --bit-clr-fg-pri | Text and chevron color of an item at rest. |
| --bit-Nav-icon-color | --bit-clr-pri | Icon color of an item at rest; kept on hover and selection unless the Accent is a semantic role. The Color parameter wins over it. |
| --bit-Nav-description-color | --bit-clr-fg-ter | Color of the description of an item. |
| --bit-Nav-disabled-color | --bit-clr-fg-dis | Text, icon, description and chevron color of a disabled item (or of every item of a disabled nav). |
| --bit-Nav-hover-background | --bit-clr-bg-pri-hover | Background of a hovered item (pointer devices only). The Accent parameter wins over it. |
| --bit-Nav-hover-color | --bit-clr-fg-pri | Text and chevron color of a hovered item. The Accent parameter wins over it. |
| --bit-Nav-pressed-background | --bit-clr-bg-pri-active | Background of an item while it is pressed (the one feedback a tap gets on a touch screen). The Accent parameter wins over it. |
| --bit-Nav-selected-background | --bit-clr-bg-pri-active | Background of the selected item, and of a collapsed branch that holds it. The Accent parameter wins over it. |
| --bit-Nav-selected-color | --bit-clr-fg-pri | Text and chevron color of the selected item, and of a collapsed branch that holds it. The Accent parameter wins over it. |
| --bit-Nav-indicator-color | --bit-clr-pri | Color of the leading bar of the selected item. The Color parameter wins over it. |
| --bit-Nav-indicator-width | --bit-shp-brd-width-thick | Thickness of the leading bar of the selected item; 0 removes it. |
| --bit-Nav-item-radius | --bit-shp-radius-control | Corner radius of an item. |
| --bit-Nav-item-min-height | spacing(6) (48px) | Smallest height of an item. The Size parameter wins over it. |
| --bit-Nav-item-padding | 4px (spacing(0.5)) | Padding of an item; the indentation of the levels is added to its start. |
| --bit-Nav-item-gap | 0 | Room between two items, at every level. |
| --bit-Nav-font-size | --bit-tpg-fs-sm | Text size of an item. The Size parameter wins over it. |
| --bit-Nav-icon-size | --bit-siz-icon-md | Icon size of an item and of a group header. The Size parameter wins over it. |
| --bit-Nav-description-font-size | --bit-tpg-fs-xs | Text size of the description of an item. The Size parameter wins over it. |
| --bit-Nav-header-color | --bit-clr-fg-pri | Text color of a group header (Grouped render type). |
| --bit-Nav-header-font-size | --bit-tpg-fs-lg | Text size of a group header. The Size parameter wins over it. |
| --bit-Nav-header-min-height | spacing(5.5) (44px) | Smallest height of a group header; one with a description grows past it. The Size parameter wins over it. |
| --bit-Nav-header-border-color | --bit-clr-brd-pri | Color of the rule under a group header. |
| --bit-Nav-header-hover-background | --bit-clr-bg-pri-hover | Background of a hovered group header (pointer devices only). |
| --bit-Nav-separator-color | --bit-clr-brd-sec | Color of a separator item. |
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: the background of the hovered and the selected item. A background, foreground or border role tints the item, a semantic role fills it and recolors its content. An explicit value wins over the --bit-Nav-* hover, pressed and selected variables; left unset, the nav takes the PrimaryBackground accent unless they say otherwise. |
| 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 chevron of a parent that has a URL, or a group header. 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. An explicit value wins over --bit-Nav-icon-color and --bit-Nav-indicator-color; left unset, the nav is primary unless they say otherwise. |
| 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 chevron of a parent that has a URL, or a group header. 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 width in px of the chevron, which the items without children keep as padding in its place so every text lines up. |
| 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 | The URL matching behavior of the nav in the Automatic mode. 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. |
| NewTabHint | string? | null | Replaces the visually hidden "(opens in a new tab)" an item whose Target is _blank is announced with, e.g. to translate it. An empty value removes it. |
| NoCollapse | bool | false | Keeps every item expanded and hides the collapse/expand buttons together with the space they reserve at the start of each item. |
| NoNewTabHint | bool | false | Stops the items whose Target is _blank from announcing that they open a new tab - only for where a visible label or heading already says so. |
| 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. An explicit value wins over the --bit-Nav-* size variables; left unset, the nav is medium unless they say otherwise. |
| 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 the children of an item are currently shown, which is always the case while NoCollapse is set. | |
| 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. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| 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. |
| 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. |
| IsDisabled | BitNameSelectorPair<TItem, bool?> | new(nameof(BitNavItem.IsDisabled)) | The IsDisabled 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. |
| Rel | BitNameSelectorPair<TItem, BitLinkRels?> | new(nameof(BitNavItem.Rel)) | The Rel 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 | 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.